Skip to main content

Rules

API

Rules allow for dynamic aspects for a form, e.g. by hiding or disabling UI schema elements.

A rule may be attached to any UI schema element and can be defined with the rule property. We'll first look at an example definition of a rule and then explain it in detail.

"rule": {
"effect": "HIDE",
"condition": {
"scope": "#/properties/name",
"schema": { enum: ["foo"] }
}
}

A rule basically works by first evaluating the condition property and in case it evaluates to true, executing the associated effect.

RuleEffect#

The effect property determines what should happen to the attached UI schema element once the condition is met. In the example above, if the name property has the value of foo, we'll hide the UI schema element the rule is attached to. Current effects include:

  • HIDE: hide the UI schema element
  • SHOW: show the UI schema element
  • DISABLE: disable the UI schema element
  • ENABLE: enable the UI schema element

The condition property describes what value should be observed and validates that value with against the JSON schema that is specified with schema. If validation succeeds the condition is fulfilled and the associated effect will be triggered.

SchemaBasedConditions have been introduced with version 2.0.6 and have become the new default. The previous format via type and expectedValue properties is still supported for the time being.