MaestroThe UI design product. | Form Builder | All versions This feature is related to all versions.
Maestro validation rules provide the ability to validate either an individual element’s value or complex, interdependent data relationships in a form. More often than not, you use client-side validation rules in a Maestro single page application. Let's look at it in more detail.
A simple validation rule for an item may check that its value contains only the letters A-Z
or a-z
. A complex rule may check that, for a joint application, all the second applicant’s details are complete.
Validation rules can be applied to individual Elements (see the image above - the top left, red highlight), Pages (middle, red highlight), or at the Form level (bottom right, red highlight).
Data Fields are calculated and have no validation rule support. The onus is on developers to ensure these calculations are accurate. If validation is required, this can be done in a related UI element validation rule or in a Page Validation rule.
Validation rules work alongside Elements marked Mandatory at design time, or at runtime if a Mandatory If rule condition is met (see the image above - yellow highlight) and Pre-Submit rules (orange highlight).
A well-designed client-side validation model will use a mix of techniques to ensure a Form is complete and correct at the time of submission.
When Validation and Mandatory rules are run depends on the validation policy setting for a form. This can be either Validate on Page Change – which means validation must be complete on a page to move forwards, or Unconstrained, validate on submit - which enforces rules only at the point of submission providing more flexibility in data entry.
Validation is not performed if the user navigates backwards to a previous page.
Mandatory data requirements, if implemented, are enforced before any validation rule is invoked and this only happens once a user has entered data into a field or changed an existing data value.
A validation rule states the conditions in which the data in a component is considered valid.
There are three types of validation rules available in Maestro:
Validation function return values are not interpreted by Maestro as truthy values as you can see from the following snippet of a generated Regular Expression rule:
var ex = new RegExp('$.*^', 'img');
return ex.test(value) || 'Fail'
The return value is truthy for both a successful match (where the boolean true is returned) and an unsuccessful match (where the string Fail
is returned).
Maestro interprets return values as follows:
Not Valid
.All other return types are ignored. This means that Object, Number, Array, etc., are treated as a successful validation (one would assume the truthiness rule would apply). However, the same applies to null
, undefined
, “”
, and other falsy values – all are ignored and the validation succeeds.
This last point is sometimes a cause for confusion.
Best practice is to return a either String in the case of a validation error, or true / undefined. For example, the rule below checks the field value is less than one million or, if it is not, returns Invalid amount
.
value < 1000000 | "Invalid amount"
Rules will be called at different stages:
How Maestro handles failed validation errors depends on the template configuration. Let's look at typical configurations in more detail.
Next, learn how to use Regular Expressions in your rules.