Execution Order
The forms designer lets you add JavaScript to your form that is executed at particular points in a form's lifecycle. The The Form Lifecycle: Control and Action Processing describes how forms are rendered and their actions processed, and The Form Helper Library has more information about writing functions.
This table describes each function/handler. They are executed in order, with those at the top of the table first.
Function/Handler | Executed | Description |
---|---|---|
Form Server-side Initialisation Handler | Server-side | The server-side initialisation handler found in the Form Settings menu. This is the first function to be executed before the page is rendered. It will be executed on every page. As this handler needs to take into account all pages, the Page Handler is often easier to use |
Page Server-side Initialisation Handler | Server-side | The server-side initialisation handler found in each page's settings. This function is executed after the form-level handler but before field default functions |
Default Functions | Server-side | Almost every field can have a default function. This property lets you enter a script that will be executed server-side as the field is generated. It is mostly used to set the value of the field. That could be by calling another service (an end point for example) or by calculating the value based on what's been entered in previous pages of the form |
Form Client-side Initialisation Handler | Browser-side | The form client-side initialisation handler. Allows you to enter script that is executed browser-side on every page once the page has been rendered. As this field needs to take into account all pages, the Page Handler is often easier to use |
Page Initialisation Client-side Handler | Browser-side | The page initialisation handler. Allows you to enter script that is executed browser-side once the page has been rendered. It is useful for showing and hiding multiple fields on a page |
Validation Function | Browser-side repeated Server-side | Almost every input field has a validation function. This property lets you enter a script that will calculate whether the value of the field is valid or not. Validation is performed browser-side as field values are updated, and repeated server-side between pages and when the form is submitted (in which case a failure will reload the page and display the error). Returning true for valid, false for invalid will display the fields default error message. Return a map in the following format to catch the errorType in a field's error message function: { |
Handlers | Browser-side | Field handlers are executed browser-side on page load and are also triggered whenever the value of the field changes. Whether the value of a field is valid or not is passed to the handler function as a parameter. The scripts you enter here will power much of the dynamic behaviour of your form. Handlers can be used to show and hide fields, update field values, disable fields, change the options available in drop-downs, to name just a few Handlers have built in protection against circular events to prevent one field updating another, which then attempts to update the original field again |
As each page of your form is requested, loaded, interacted with and submitted, the following cycle takes place.
The cycle starts at the top, with a browser making a request to your site for a form. The form is then rendered in the first blue block, and appears to the user at the beginning of the first green block.
Function Signature Parameters
The following parameters are passed to the various functions described in this document.
Name | Description |
---|---|
context | Contains any context variables generated by the site framework |
currentValue | The current value of the field, this may be undefined |
defaultErrorMessage | The default error message a field may display |
defaultPage | Used in navigation functions. The page that would be navigated to if this function wasn't present |
defaultPageInstance | Used in navigation functions. The page instance that would be navigated to if this function wasn't present |
defaultValue | The default value of the field. This is normally the value of the DEFAULT property |
errorType | The type of error thrown by a field failing validation. See Error Message Functions for the full list of types |
eventName | Either "CHANGE" (the value has changed), "NEWPAGEINIT" (the page is loading for the first time) or "PAGEINIT" (the page is loading) |
fieldName | The name of the field firing the event |
helper | The form helper library |
mode | Whether the form is being rendered in: |
optionData | The options in list-type fields |
pageInstance | The instance number of the page, this will be 0 for a new page, 1 for a page that exists in the form session data (ie a page that has been submitted) |
pageName | The name of the page about to be displayed |
processor | The skeleton processor |
props | Contains any properties |
sessionData | The current session data storing (amongst other things) the values of fields submitted so far |
valid | true if the field passed validation, false if it failed |
value | The value of the field |
Form and Page Function Signatures
Form Level Server Init Handler: FORMINITHANDLERSERVER
A form level property containing a server-side initialisation function. It must be a function.
function(helper, pageName, pageInstance, mode) {
// Perform any initialisation...
if (mode === "normal") {}
}
Form Level Client Init Handler: FORMINITHANDLER
A form level property containing a browser-side initialisation function. It must be a function.
function(helper, pageName, pageInstance) {
}
Page Level Server Init Handler: PAGEINITHANDLERSERVER
A page level property containing a server-side initialisation function. It must be a function.
function(helper, pageName, pageInstance, mode) {
// Perform any initialisation...
if (mode === "normal") {}
}
Page Level Client Init Handler: PAGEINITHANDLER
A page level property containing a browser-side initialisation function. It must be a function.
function(helper, pageName, pageInstance) {
}
Button Function Signatures
Button - Wizard: NEXTFUNCTION
A field level property on the wizard button field to calculate the next page. It must be a function. The function should return the name of the page to display.
function(helper, defaultPage, sessionData, defaultPageInstance) {
return defaultPage;
}
Button - Wizard: BACKFUNCTION
A field level property on the wizard button field to calculate the previous page. It must be a function. The function should return the name of the page to display.
function(helper, defaultPage, sessionData, defaultPageInstance) {
return defaultPage;
}
Button - Navigation: NAVFUNCTION
A field level property on the navigation button field to calculate the page to navigate to. It must be a function. The function should return the name of the page to display.
function(helper, defaultPage, sessionData, defaultPageInstance) {
var thePage;
// set the page to go to...
return thePage;
}
Button - Navigation: SHOWFUNCTION
A server-side field level property on the navigation button field to determine if the button should be shown. It must be a function. The function should return true to show the button.
function(helper) {
var showButton = true;
// determine if button should be shown...
return showButton;
}
Button - Script Button: SCRIPT
The code to execute when the script button is pressed. It must be a function.
function(helper) {
}
Input Field Function Signatures
Field - Default Function: DEFFUNC
A field level property available on some field types. It must be a function. The function should return the value of the field. Without a default function this would be the defaultValue if currentValue is undefined, otherwise the currentValue.
function(helper, defaultValue, currentValue) {
var theValue;
if (currentValue !== undefined) {
theValue = currentValue;
} else {
theValue = defaultValue;
}
return theValue;
}
Field - Event Handlers: HANDLERS
A field level property available on many field types. It must be a function.
function(helper, fieldName, value, valid, eventName) {
if (eventName == 'CHANGE' && valid) {
// perform action...
}
}
Field - Validation Function: VALFUNC
A field level property available on many field types. It must be a function. The function should return true if the field value is valid, false if it is invalid.
Alternatively, return an object with the keys isValid and errorType to pass custom errors to the error message function.
function(helper, value) {
var isValid = true;
return isValid;
}
Field - Error Message Function: ERRMSGFUNC
Used to generate a custom error message, depending upon the errorType thrown by the field. See Error Message Functions for a full description.
function(helper, errorType, defaultErrorMessage) {
var errorMessage = defaultErrorMessage;
// set error message based on errorType...
return errorMessage;
}
Field - Options Function: OPTIONSFUNC
Used in the radio group, checkbox group, list box and drop-down list field to generate the options displayed.
function(helper, optionData) {
// update optionData...
return optionData;
}
Layout Field Function Signatures
Layout - Conditional Layout: CONDFUNCTION
A field level property on the conditional layout field type. It must be a function. The function should return true to render the contained fields, false to ignore them. Note that fields in the layout are not simply hidden, they are not present on the form at all.
function(helper) {
var showFields = true;
return showFields;
}
Layout - Accordion Layout: COLLAPSEDFUNC
A field level property on the accordion layout field. It must be a function. Return "collapsed" or "expanded" to control the behaviour of the layout when first displayed.
function(helper) {
// The collapsed state can be either "collapsed" or "expanded"
var collapsedState = "collapsed";
return collapsedState;
}