傳回表單或表單上項目的參考,視方法的呼叫位置而定。
語法
ExecutionContextObj.getFormContext()
返回值
類型:物件
描述:傳回表單或表單上項目的參考,例如可編輯格線,視方法的呼叫位置而定。 此方法可讓您建立通用事件處理常式,這些處理常式可以根據呼叫位置在表單或表單上的專案上進行操作。
Example
下列範例程式碼示範如何建立方法,根據您註冊指令碼的位置,在表單欄或可編輯的格線儲存格上設定通知 (欄 OnChange 事件或可編輯格線 OnChange 事件):
function commonEventHandler(executionContext) {
var formContext = executionContext.getFormContext();
var telephoneAttr = formContext.data.entity.attributes.get('telephone1');
var isNumberWithCountryCode = telephoneAttr.getValue().substring(0,1) === '+';
// telephoneField will be a form control if invoked from a form OnChange event;
// telephoneField will be a editable grid GridCell object if invoked from editable grid OnChange event.
var telephoneField = telephoneAttr.controls.get(0);
if (!isNumberWithCountryCode) {
telephoneField.setNotification('Please include the country code beginning with '+'.', 'countryCodeNotification');
}
else {
telephoneField.clearNotification('countryCodeNotification');
}
}