Expressions
You use expressions in the component definition file to control field visibility based on the configuration of another field in the same component. Depending upon the complexity of the expression, you can also build an expression with multiple operators and comparators.
Categories of expressions
The following categories of expressions are available:
- Boolean expressions
- Compares two values or variables and returns a Boolean result based on the comparison.
- Unary operator
- Evaluates the expression by using a single operator and returns a Boolean result.
- Binary operator
- Evaluates the expression by using two operators, such as != or ==, and returns a Boolean result.
String-based expressions include:
- CONTAINS and NOT_CONTAINS
- Evaluates the expression based on whether a string contains, or does not contain, the specified characters.
- ENDS_WITH and NOT_ENDS_WITH
- Evaluates the expression based on whether a string ends with, or does not end with, the specified characters.
- IS_IN_LIST and IS_NOT_IN_LIST
- Evaluates the expression based on whether the string is present in a specified list.
- IS_NULL and IS_NOT_NULL
- Evaluates the expression based on whether the variable has a value, or is blank.
- STARTS_WITH and NOT_STARTS_WITH
- Evaluates the expression based on whether the string begins with, or does not begin with, the specified characters.
Supported operators
You can use the following operators in expressions:
- AND (&&)
- All conditions must be true for the expression to evaluate as true.
- Equal to (==)
- Variables on both sides of the operator must match.
- Greater than (>)
- Value must be greater.
- Greater than or equal to (>=)
- Value must be greater than, or equal to.
- Less than (<)
- Value must be lower.
- Less than or equal to (<=)
- Value must be lower than, or equal to.
- Not equal to (!=)
- Value must not be equal to.
- OR (||)
- Any condition must be true for the expression to evaluate as true.
Referencing other properties in expressions
You can build expressions that reference other properties in the component
definition. Use $this
in the expressions in such cases. The
following example shows a visibility-based expression that references the
columnWidth
attribute:
Composite expressions
You can also combine multiple expressions into a single expression by enclosing the individual expressions within parenthesis.
Using expressions to control field visibility
In the following example, the Employee ID field is based on an Integer custom component. The input in one of the fields uses an expression that controls the visibility of a checkbox in the component. The following figure shows the field property pane with the checkbox and the field setting, on which its visibility depends:
The system requires the Show thousands separator checkbox to be visible when you set the Display as field to either Input or Stepper.
The following example code snippet shows the configuration of the Display as field in the component definition file:
{
"name": "displayAs",
"label": "Display as",
"format": “SELECT",
"defaultValue": "input",
"source": [
{
"key": "input",
"value": Input"
},
{
"key": "stepper",
"value": "Stepper"
},
{
"key": "slider",
"value": "Slider”
}
]
}
You can use the following example of an expression in the visibility
attribute of the checkbox to evaluate this
condition:
{
"name": "showGroupSeparators",
"label": "Show thousands separator",
"format": "BOOLEAN",
"visibility": "$this.displayAs != 'slider'"
}
Other valid configurations include the following examples:
"$this.displayAs == 'input' || $this.displayAs == 'stepper'"
"$this.displayAs IS_IN_LIST 'input,stepper'"
"($this.displayAs = 'input' || $this.thing1 > 5) && $this.thing2 IS_NULL"
Previous topic Annotations