Skip to content
FormQL edited this page May 27, 2019 · 20 revisions

Overview

Rules are a set of expressions that control the state of each component in the form.

Type of rules

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.

Condition expression

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 FormQL Editor - Rules - Calculated Field

Example 1 - Editing calculated field in a form

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 FormQL Editor - Rules - Calculated Field Example

Example 2 - Editing hidden rule condition

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 FormQL Editor - Rules - Calculated Field Example

Try yourself in this Stackblitz example