On Validate
Last updated 25/07/2025
This documentation will demonstrate how the On Validate event works. The On Validate event is a client-side event. After a value has been entered into a form field and a user leaves the field, the function attached to the On Validate event will execute and create an error which will display a message if there is an invalid value in the field. The user will be forced back to the field to change the data.
The Orders application is used to demonstrate the On Validate event.
Execute an On Validate Event
The GetProductPrice query gets the ProductKey, Name, Price, and Quantity fields from the Product table. The product names will be listed in the Product field's lookup on the Order Items form. The Quantity query field is provided as metadata to the Order Items form when attached as a _LookupQuery providing how much stock is available for the selected product. This metadata can then be used by a function attached to the form.
The GetProductPrice query also has the Price field supplied as metadata and this is being used for the On List Select event.
SELECT
Product.ProductKey AS ProductKey,
Product.Name AS Name,
Product.Price AS Price,
Product.StockQuantity AS Quantity
FROM
Product
The GetProductPrice query is saved in the Queries view in Five.


The
function GetAvailableQuantity(five, context, result) {
const qty = parseInt(five.field.Quantity);
if (qty > five.getMetadata('ProductKey', 'Quantity')) {
return five.createError(result, "Sorry, we don't have that quantity available!");
}
return five.success(result);
}
The

The GetProductPrice query is attached to the Product field with a display type of _LookupQuery on the Order Items form. The metadata to this field can now be used by the

The

In the Orders application, you can see all the products and the quantity available in the Products view. If we select a customer and drill down to place an order on the Order Items page on the Orders form, when a quantity is entered into the Quantity field that is larger than the amount available in the system an error will be created and the user will receive a message and be forced to change the quantity.
