Scope object in custom functions
In Adaptive Forms, a scope object is passed as the last argument to functions when a rule is executed. It can be used to read form/field properties and modify the form from within the functions. The scope object contains a read-only proxy object for the form, the triggered event, and the target field. Form and field properties can be accessed using the scope object by appending $, for example, scope.form.$id and scope.field.$id, respectively.
Form modification functions using scope object
Scope object has following functions for form modification:
Function
Syntax
Description
Code sample
setProperty
setProperty(any $element, any $payload)Sets a property on the target field using the
$payload.Click here to view the example.
validate
validate([any $element])Runs validation on the target field. Runs validation on the entire form if no target is provided, and returns an array of validation errors.
Click here to view the example.
reset (deprecated)
reset([any $element])Deprecated. Use
dispatchEvent($target, 'reset') instead. Resets the target field or, if no target is provided, resets the entire form.Click here to view the example.
importData
importData(any $payload)Imports data into the form, replacing any existing form data. If
qualifiedName is specified, data is imported into that container field only.Click here to view the example.
submitForm
submitForm(any $data [, boolean $validate_form = true, string $submit_as = 'multipart/form-data'])Triggers a form submission. You can specify what to submit via the
$payload parameter and set the content type via the $contentType parameter. Data is submitted as multipart/form-data by default. The optional $validateForm parameter specifies whether the form should be validated before submission (default: true). Upon success, submitSuccess is fired; on failure, submitError is fired.Click here to view the example.
setFocus
setFocus(any $element [, FocusOption $focusOption])Sets the focus to the target field, which can be a panel or form field. If no target is provided, focus is set to the field that triggered the rule. The optional
$focusOption parameter specifies whether the next or previous item relative to the target should be focused. Supported values: 'nextItem', 'previousItem'. If used with a panel, navigation is restricted to that panel. If used with a field, navigation occurs within the parent panel of that field.Click here to view the example.
dispatchEvent
dispatchEvent(any $element, string $eventName [, any $payload])Dispatches an event of type
$eventName on the element determined by $target. If no target is provided, the event is dispatched on the form. The optional $payload is available to expressions handling the event. The optional $dispatch parameter controls event propagation behavior.Click here to view the example.
markFieldAsInvalid
markFieldAsInvalid(string $fieldIdentifier, string $validationMessage [, any $option = {useId: true}])Marks the field identified by
$fieldIdentifier as invalid and displays the $validationMessage. The optional $option parameter specifies whether $fieldIdentifier is interpreted as id, dataRef, or qualifiedName. The default value is {useId: true}. Supported values: {useId: true}, {useDataRef: true}, {useQualifiedName: true}.Click here to view the example.
See Also
- Introduction to Rule Editor for Adaptive Forms based on Core Components
- Operator types and events in rule editor of an Adaptive Form based on Core Components
- Rule Editor User Interface for Adaptive Forms based on Core Components
- Different use cases of Rule Editor for an Adaptive Form Based on Core Components
- Difference in various editions of Rule editor
- Using asynchronous functions in an Adaptive Form
- Invoke Service enhancements in the Visual Rule Editor for forms based on Core Components
- Introduction to Custom Functions for Adaptive Forms based on Core Components
- Create a Custom Function for an Adaptive Form based on Core Components
- Scope object in custom functions
- Examples of developing and using a custom function
recommendation-more-help
fbcff2a9-b6fe-4574-b04a-21e75df764ab