On Exit
Last updated 30/11/2021
On Exit Event
The OnExit
event executes on the client
.
Function Signature
OnExit(sender, context, result) : FiveError;
Parameter | Type | Description |
---|---|---|
sender | FormField | An instance of the form field object. |
context | Map<string,any> | Optional map of string to values. |
result | FiveError | A Five error to set the result and return the error. |
Description
When a user exits the field either by pressing the Tab button or clicking out of the field, the event will be detected and the code will execute.
Example
In the Portfolio application, we have the two forms Buys and Sells with the Quantity, Price, Fees and Total fields. We can write a function and attach it to the Fees field's On Exit event to calculate the total price. As the user exits the Fees field the code will be executed to calculate the total.
Figure 1 - Populate the Total field on exit of the Fees field
The below function is perfoming the following:
- Uses
form.internal.ActionID
to get the form's identifier. - Uses
form.internal.ActionID
to get the form's identifier. - Uses form.field.FieldID to get the fields from the form.
- When on the Buys form, multiply the quantity and price and add the fees.
- When on the Sells form, multiply the quantity and price and subtract the fees.
function CalculateTotal(sender: any, context: any, result: FiveError) : FiveError {
if (form.internal.ActionID == 'Buys') {
form.field.Total = form.field.Quantity * form.field.Price + form.field.Fees
} else {
form.field.Total = form.field.Quantity * form.field.Price - form.field.Fees
}
return five.Success(result, null);
}
Prerequisites
- Function must be saved in the Functions view.
- Form must be saved in the Forms view.
Steps to Attach a Function to the On Exit Event
- Select Forms in the menu.
- Select the required form record in the list.
- Click the Pages tab.
- Select the required form page record.
- Click the Fields tab.
- Select the required form field record.
- Click the Events tab.
- Click the Edit button in the form app bar.
- Use the lookup icon in the On Exit field and select the Function ID.
- Click the Save button in the form app bar.
- Click both Save buttons in the stacked form app bars.
Figure 1 - Attach a function to the On Exit event
info
This same function can be added to the Sells form Fees field to subtract the fees when not on the Buys form.