-
Notifications
You must be signed in to change notification settings - Fork 22
Rules
Rules are a set of expressions that control the state of each component in the form.
FormQL comes with 4 types of rule, there is also the ability to create custom rules (see Custom validators)
-
Calculated Field: this rule calculates a component value based on a static or dynamic value. Static being a fix value (e.g. the value of a field to be always
true
) and a dynamic value is a rule that depends on another values (e.g. contact.firstName + " " + contact.lastName). It's recommended that components that use this rule should also be read only - Hidden: this rule hides the component if the condition expression evaluates to true.
- Read Only: makes the component read only if the condition expression evaluates to true.
- Required: makes the component required if the condition expression evaluates to true. There is also the ability to write an error message that will be displayed when the form is validated and the field is not populated.
The expression used on every rule is a JavaScript expression that gets evaluated against the data generated by the fields in the form. The data structure is driven by every component schema name in the form (see schema property in Component Properties).
When editing a component in FormQL Editor, the rules are evaluated in real time and the result shown below the expression
In the gif below, the calculated field in a form is being changed, the result and an error is displayed while typing in the expression for calculated fields
In the gif below, a component with a textarea field is being edited and a value is shown with the result in real time. Note that fields marked as hidden are still shown in FormQL Editor but with a red background, the field will be hidden in a View Mode
Try yourself in this Stackblitz example