Form Scripting¶
Emakin forms support scripting for custom behavior and dynamic form interactions. Scripts can execute operations before a form is rendered or respond to changes in the data model. Library functions like $Xml provide essential data operations.
Form Fields and Data Manipulation¶
Form data is accessible through the global variable $Xml. All form data elements can be referenced and manipulated using standard XPath expressions.
To retrieve the value of a specific form field, the $Xml.Evaluate
function is used:
1 |
|
All form data is inherently stored in an XML structure, with field values represented as string types. To work with values as different data types, you can utilize the following dedicated functions for type conversion:
- Xml.EvaluateBoolean: Evaluates the expression and returns a boolean value.
- Xml.EvaluateNumber: Evaluates the expression and returns a numerical value.
- Xml.EvaluateDateTime: Evaluates the expression and returns a Date/DateTime object.
For example, to retrieve a date field's value as a Date
object:
1 |
|
To modify the values of form fields, the Xml.SetValue function is employed:
1 |
|
The SetValue
function intelligently handles the data type of the provided value and automatically converts it to the appropriate standard XML format for storage.
1 2 |
|
As XML supports the storage of hierarchical data structures, you can create lists of multiple values. This is particularly useful for supporting tabular or grid layouts within forms.
1 2 3 |
|
Please refer to Xml page for further details.
$Form Variable Overview¶
The $Form
variable provides access to form properties and functions for managing form elements dynamically.
1 2 3 4 5 6 7 8 |
|
Change Form Section States Dynamically¶
Form section states are defined by task properties but can also be updated dynamically through scripting.
1 2 3 |
|
Available Section States:
State | Description |
---|---|
(Empty) | Default state |
Hidden | Hides the section |
Disabled | Makes section read-only |
Attach Change Events¶
Use the $Xml.Bind
method to attach a change event to an existing element in the data model.
1 2 3 |
|
For elements that may not exist at the time of form rendering, use the $Xml.Live
method. It attaches event listeners to future elements when they are created.
1 2 3 |
|