Skip to main content

On Enter

Last updated 30/11/2021

On Enter Event

The OnEnter event executes on the client.

Function Signature
OnEnter(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 enters the field either by pressing the Tab button or clicking in 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 Total field's On Enter event to calculate the total price and populate the value in the field as a user enters the field.

Populate the Total Field on Enter
Figure 1 - Populate the Total field on enter

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 Enter 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 Enter 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 Enter Event
Figure 2 - Attach a function to the On Enter event

info

This same function can be added to the Sells form Total field to subtract the fees when not on the Buys form.