Toggle menu

Writing a Custom Function

This article describes using a form's initialisation handler to define a custom function. That function is then used by the onclick events of buttons in a Handlebars template.

Writing the Function

Add your custom function to the client initialisation handler in the page or form settings. This will mean it's available on a given page while a user is interacting with your form - it won't be available in any server-side functions.

Page Settings Init Handler
 

In the example below, the function will update the values of fields with the supplied arguments, then show or hide a field based upon the value of the action:

function(helper, pageName, pageInstance) {
    performAction = function(message, action) {
        helper.updateFieldValue("TEXTINPUT", message);
        helper.updateFieldValue("ACTION", action);
        if (action === "SHOW") {
            helper.showField("ACTION");
        } else if (action === "HIDE") {
            helper.hideField("ACTION");
        }
        return true;
    }
}

Calling the Function

This Handlebars templates generates two buttons. Each button has an onclick handler which calls the custom function. Note how, because two buttons are being generated by the same template, and index has to be set so that they can be distinguished from each other.:

{{SCRIPTBUTTON label="Show" index="0" onClick="performAction('Show','SHOW')"}}
{{SCRIPTBUTTON label="Hide" index="1" onClick="performAction('Hide','HIDE')"}}

Example

Here's the working form, which is also in the downloads area.

Share this page

Facebook icon Twitter icon email icon

Print

print icon