Conditional Expressions
Overview
Conditional expressions in Studio control the visibility and behavior of form elements dynamically based on the current record’s data. They are used extensively on custom fields and in the Visual View Builder to create responsive forms that adapt to user input.
Condition Types
Studio supports five types of conditional expressions:
| Condition | Generated Attribute | Description |
|---|---|---|
Show if |
|
The element is visible only when the expression evaluates to true. When false, the element is hidden but its data is still present. |
Hide if |
|
The element is hidden when the expression evaluates to true. Inverse of Show if. |
Required if |
|
The element becomes mandatory when the expression evaluates to true. The form cannot be saved without a value. |
Read-only if |
|
The element becomes non-editable when the expression evaluates to true. The value is displayed but cannot be changed. |
Collapse if |
|
For panels only. The panel is collapsed when the expression evaluates to true. |
|
Show if / Hide if are UI-only: These conditions control visibility in the user interface, but the field data remains accessible through the REST API. Do not use |
Expression Syntax
The $record Prefix
In XML view conditions (used in View Extension mode), field references use the $record. prefix to access the current record’s values:
$record.fieldName == 'value'
This prefix is specific to the Axelor view engine and ensures the expression references the current form record’s data.
Basic Comparisons
| Expression | Meaning |
|---|---|
|
True when the status field equals "draft" |
|
True when the amount is greater than 1000 |
|
True when amount is between 0 and 100 |
|
True when the type is not "internal" |
Null and Empty Checks
| Expression | Meaning |
|---|---|
|
True when the partner field has a value |
|
True when the partner field is empty |
|
True when the name is not null and not empty |
Boolean Fields
| Expression | Meaning |
|---|---|
|
True when the isActive checkbox is checked |
|
True when the isActive checkbox is unchecked |
|
Explicit check (equivalent to |
Practical Examples
Example 1: Show Payment Fields for Confirmed Orders
Show payment-related fields only when an order is confirmed and the total amount is positive:
-
Show if:
$record.status == 'confirmed' && $record.totalAmount > 0
Apply this condition to a panel containing payment method, payment date, and payment reference fields.
Example 2: Make Email Required for Customers
Require an email address when the contact type is "Customer":
-
Required if:
$record.contactType == 'customer'
Apply this condition to the email field.
Conditions on Custom Fields vs. View Elements
There are two contexts where conditions are used:
On Custom Fields (MetaJsonField)
When you set conditions on a custom field (via the Custom Fields form or the View Builder properties panel), the condition is stored as a field attribute and applies wherever the field is rendered.
The condition properties are mapped as follows:
| Field Property | Generated XML Attribute |
|---|---|
|
|
|
|
|
|
|
|
Condition Limitations
-
Conditions are evaluated client-side in the browser. They cannot call server-side methods or execute database queries.
-
Complex Groovy expressions are not supported in condition fields. Use simple JavaScript-like expressions.
-
For server-side validation, use Script actions triggered by
onChangeoronSaveevents.
|
Keep conditions simple and readable. If a condition becomes too complex, consider splitting it into multiple fields with individual conditions, or use a computed boolean field with a Script action to set its value. |
Related Pages
-
Custom Fields — Setting conditions on fields
-
Visual View Builder — Setting conditions in the properties panel
-
Actions — Server-side logic for complex validations