Back

Server Event Basics


Events provide an opportunity to programmatically customise the behaviour of your applications. Events whose Event Handlers execute code on the Server are known as Server Events.

Server Events are configured by adding JavaScript Scripts to their Event Handlers.

Once triggered, Event Handers execute all their configured Scripts in order. Should a Script terminate prematurely (either programmatically or due to an unexpected error) no further Scripts in the Event Handler are executed.

Server Events fall into three broad categories: Lifecycle, User and Validation Events.

Lifecycle Events are closely linked to the state of their owner. The most useful lifecycle event is the Before Event, which is triggered when the owner of the Event is instantiated. It provides an opportunity to perform security checks and to set up the initial state of the Event owner. For example, a Form’s Before Event is triggered when a user navigates to that Form for the first time and can be used to load some initial data and to make sure that user has permission to visit the Form.

User Events are triggered in response to some action, for example, a user clicking on a button in their browser. When a User Event is triggered, data already entered by the user is transferred to the Server. The Server then iterates over every Control on the Page updating them with any entered data, until it reaches the User Event’s owning Control. All Scripts in the User Event’s Event Handler are then executed in order.

Validation Events are triggered during User Event processing, as the Server is interating over and updating Controls with user entered data. When the Server arrives at a Control with a configured Validation Event, all the Scripts in its Event Handler are executed in order. If a Script in the Validation Event Handler detects invalid information, it can terminate the User Event and return an appropriate message to the user. For example, a Validation Event could be used to test the complexity of an entered password and if it fails, it can send an informative message back to the user.

Sometimes, the same business logic is appropriate for more than one Server Event, for example, to validate phone numbers or to perform security checks to restrict certain features to certain users. This logic can be added as JavaScript functions to Shared Functions Scripts.

Shared Functions can be configured in the Form Properties dialog, opened by clicking on the Form Properties button in the Form Editor’s toolbar and going to the Events tab.

Any number of Shared Function Scripts can be added, and each Script can contain any number of functions.

Shared Function Scripts are processed in the configured order. Functions in Scripts further down the order will overwrite functions with the same name in Scripts higher up the order.

Event Handlers belonging to the Form, its Pages and their Controls can call any function included in any configured Shared Functions Script. Shared functions execute in the same context, and have the same access to Fields, Tables, and other resources as the calling Event Handler Script.