Skip to content

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 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
$Form = {
    element: $('form'),       // jQuery form element
    refresh() {
        // method to re-build and render form from the scratch
    },
    readonly: boolean,        // Specifies whether the form is in readonly or in edit mode
    sections: {}              // List of form sections
}

Change Form Section States Dynamically

Form section states are defined by task properties but can also be updated dynamically through scripting.

1
2
3
if ($Xml.EvaluateBoolean('SomeCondition')) {
    $Form.sections['MySection'] = 'Hidden';     // set MySection to Hidden state.
}

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
$Xml.Bind('Person/Name', function () {
    // executed when Person/Name is changed
});

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
$Xml.Live('List/Item/Amount', function () {
    // executed when List/Item/Amount is changed
});