Skip to main content

On Exit

Last updated 30/11/2021

On Exit Event

The OnExit event executes on the client.

Function Signature
OnExit(sender, context, result) : FiveError;

ParameterTypeDescription
senderFormFieldAn instance of the form field object.
contextMap<string,any>Optional map of string to values.
resultFiveErrorA 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.

Populate the Total Field on Exit of the Fees Field
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

  1. Select Forms in the menu.
  2. Select the required form record in the list.
  3. Click the Pages tab.
  4. Select the required form page record.
  5. Click the Fields tab.
  6. Select the required form field record.
  7. Click the Events tab.
  8. Click the Edit button in the form app bar.
  9. Use the lookup icon in the On Exit field and select the Function ID.
  10. Click the Save button in the form app bar.
  11. Click both Save buttons in the stacked form app bars.
Attach Function to the On Exit Event
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.