Dynamic forms
Purpose of Expressions
Expressions allow flexible, intelligent forms to be created that adapt to their context and only display relevant fields. Based on other field values, expressions can be used to define whether a field is:
- shown or hidden (
hide) - disabled (
props.disabled) - required (
props.required) - or dynamically assigned other properties
Evaluation happens at runtime, before a form is displayed.
Basic Principle
An expression is a JavaScript expression that is evaluated to true or false.
The expression is re-evaluated whenever relevant values in the form change.
Typical use cases: - A field is only displayed when another field has a specific value. - A field is hidden when another field is filled. - A field is only displayed when a record is created for the first time.
Available Variables
The following variables are available inside an expression:
data
Contains the entire form model (all current field values).
This allows other fields to be queried.
Example:
data.invoiceNr === '123'
The current field is hidden when the invoice number equals 123.
mode
Defines the context in which the form is displayed.
Possible values:
- create – form for creating a new record
- edit – form for editing an existing record
- view – form for viewing (read-only)
Example:
mode === 'create'
The field is only displayed during creation.
field
Contains metadata of the current field (key, type, properties).
This variable is usually only required for advanced use cases.
Typical Examples
Hide a field when another field is empty
!data.customerId
Show a field only in edit mode
mode === 'edit'
Show a field only when a value is greater than 100
data.amount > 100
Disable a field once a status is set
(as a property expression)
data.status === 'final'
Usage Notes
- Expressions must be valid JavaScript.
- The return value must be
trueorfalse. - Only simple conditions should be used.
- Complex logic should be avoided.
- Invalid expressions may cause fields to be rendered incorrectly.
Benefit
Expressions make it possible to adapt forms flexibly without modeling additional processes or special logic.