getFormContext (Client API reference)
Returns a reference to the form or an item on the form depending on where the method was called.
Syntax
ExecutionContextObj.getFormContext()
Return value
Type: Object
Description: Returns a reference to the form or an item on the form such as editable grid depending on where the method was called. This method enables you to create common event handlers that can operate either on a form or an item on the form depending on where its called.
Example
The following sample code demonstrates how you can create a method that sets notification on a form column or editable grid cell depending on where you registered the script (Column OnChange event or editable grid OnChange event):
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');
}
}
Related articles
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈