Overview
Rules allow you to conditionally show, hide, enable, or disable UI schema elements based on the current form data. This enables dynamic forms that adapt to user input.Rule Structure
A rule consists of two parts:Rule Effects
Four rule effects are available:Condition Types
Leaf Condition
Compares a value at a specific scope to an expected value:lastName field only shows when firstName equals “John”.
Schema-Based Condition
Validates data against a JSON Schema:zipCode field is enabled only when country is “US”.
Using failWhenUndefined:
Validate Function Condition
Uses a custom validation function:OR Condition
Combines multiple conditions with OR logic:AND Condition
Combines multiple conditions with AND logic:Rule Evaluation
Rules are evaluated in the following manner:Visibility Evaluation
Enablement Evaluation
Common Patterns
Show Field Based on Checkbox
Enable Field Based on Selection
Complex Nested Conditions
Rules on Layout Elements
Rules can be applied to any UI schema element, including layouts:Utility Functions
JSON Forms provides utility functions for working with rules:Best Practices
- Use SHOW instead of HIDE:
SHOWrules are more intuitive thanHIDErules - Keep conditions simple: Complex nested conditions can be hard to maintain
- Validate your rules: Test edge cases and ensure rules behave correctly
- Consider performance: Rules are evaluated on every data change
- Document complex rules: Add comments explaining the business logic
- Use schema-based conditions: They’re more powerful than leaf conditions for complex validations
- Leverage AND/OR: Compose simple conditions rather than creating complex custom validators
Debugging Rules
To debug rule evaluation:- Check the current form data
- Verify the scope paths in your conditions
- Ensure expected values match exactly (including type)
- Test each condition independently
- Use browser dev tools to inspect the rule evaluation logic