Only valid as a child of a validation trait, validator
declares a validation
rule to check user input in a form, and prevent form submission unless the validation check is
successful.
Fields
Field | Description |
---|---|
id |
Identifies the control when it is referenced in data-binding queries, reports, and workflow scripts. |
Remarks
A validator
element is valid only as the child of a validation trait. If a declarations
trait is
also declared, the optional validation
trait must be placed immediately after
it in the XML hierarchy. If no declarations
is present,
validation
needs to be the first child element of its parent.
The query in cond
returns a boolean expression: the result of a comparison
can be true
, false
, or NULL
. A validation
rule fails if the comparison evaluates to false
- otherwise, the control
passes
validation.
... <textbox label='The validation rule evaluates to NULL' text='Null is valid'> <validation> <validator cond='{NULL}' message=''/> </validation> </textbox> <textbox label='The validation rule evaluates to true' text="True is valid"> <validation> <validator cond='{text == "True is valid"}' message='{text}'/> </validation> </textbox> <textbox label='The validation rule evaluates to false' text="False is invalid"> <validation> <validator cond='{text == "True is valid"}' message='{text}'/> </validation> </textbox> ...
If you declare more than one validator
element on the same control, their
validation rules will be evaluated, and their error messages will be displayed independently
of each
other.
... <numberbox label="Validation rules are evaluated independently" numberFormat='{decimalSeparator:"."}'> <validation> <validator cond='{number > 0}' message="Enter a number over 0"/> <validator cond='{number > 1}' message="Enter a number over 1"/> <validator cond='{number > 2}' message="Enter a number over 2"/> <validator cond='{number > 3}' message="Enter a number over 3"/> <validator cond='{number > 4}' message="Enter a number over 4"/> </validation> </numberbox> ...
Validation rules in a form are not evaluated until the first time the user
makes a change to a control that the cond
query references, or attempts to
submit the form. From then on, validation rules are continuously evaluated, like any other
query expression.
When the user tries to submit a form with one or more controls with
failed validation rules, the preset validation error messages are displayed next to the
invalid controls, and the message N
error(s) in
form appears in the form header. Click the message to display the validation
summary; click any of the items in the summary to go directly to the invalid control that
triggered that error.
Sample
<form id='validatorSample' menuName='Validation' platforms='web' xmlns="http://schemas.mobilengine.com/fls/v1"> <textbox label='Required text'> <validation> <validator cond='{text != ""}' message='This field is required.'/> </validation> </textbox> <checkbox id='terms' text='I have read and agree to the Terms & Conditions'> <validation> <validator cond='{terms.checked}' message='You need to agree to the terms'/> </validation> </checkbox> <datepicker id='start' label='From' dateFormat='(dtf yyyy"/"MM"/"dd)'> <validation> <validator cond='{date >= sysp.dtlFormOpen}' message='Date can't be earlier than today'/> </validation> </datepicker> <datepicker id='end' label='To' dateFormat='(dtf yyyy"/"MM"/"dd)'> <validation> <validator cond='{(dtl 2018-03-19T00:00:00) > date}' message='Date can't be later than expiry date'/> </validation> </datepicker> <datepicker label='Pick a date between start and end' dateFormat='(dtf yyyy"/"MM"/"dd)'> <validation> <validator cond='{date BETWEEN start.date AND end.date}' message='Date must be between the start and end dates'/> </validation> </datepicker> <dropdown choices='{SELECT r.words, r.more_words FROM randomWord r}' keyMap='{words}' textMap='{more_words}'> <validation> <validator cond='{selectedKey IS NOT NULL}' message='You need to select an option'/> </validation> </dropdown> <textbox label='Enter a random word'> <validation> <validator cond='{text IN (SELECT q.words FROM randomWord q)}' message='That's not random enough'/> </validation> </textbox> </form>
An overview of the types of validation
A workflow script running in the Mobilengine Cloud would access the validated submission of the webform above in the following format:
{... terms: {checked: true}, start: {date: 2015.08.26. 0:00:00 (Dtl)}, end: {date: 2015.12.17. 0:00:00 (Dtl)}, selectedKey: "hogwash", selectedText: "tiger", selectedValue: {words: "hogwash", more_words: "tiger"} ...}
See the workflow script reference guide for more details on data type mapping.