Rule Editor for Dynamic Forms in Universal Editor
The Rule Editor allows authors to turn static forms into responsive, intelligent experiencesâwithout writing code. You can conditionally show fields, perform calculations, validate data, guide users through flows, and integrate business logic that adapts as people type.
What youâll learn
By the end of this guide, you will be able to:
- Understand how rules work and when to use different rule types
- Enable and access the Rule Editor in Universal Editor
- Create conditional logic to show or hide fields dynamically
- Implement automated calculations and data validation
- Build custom functions for complex business rules
- Apply best practices for performance, maintainability, and UX
Why use the Rule Editor?
- Conditional logic: Show relevant fields only when needed to reduce noise and cognitive load.
- Dynamic calculations: Compute values automatically (totals, rates, tax) as users type.
- Data validation: Prevent errors early with real-time checks and clear messages.
- Guided experiences: Lead users through logical steps (wizards, branching).
- No-code authoring: Configure powerful behavior through a visual interface.
Common scenarios include tax calculators, loan and premium estimators, eligibility flows, multi-step applications, and surveys with conditional questions.
How rules work
A rule defines what should happen when a condition is met. Conceptually, a rule has two parts:
- Condition: A statement that evaluates to true or false.
- Examples: âIncome > 50,000,â âCoverage = âYesâ,â âField is emptyâ
- Action: What occurs when the condition is true (and optionally, when it is false).
- Examples: Show/Hide a field, Set/Clear a value, Validate input, Enable/Disable a button
-
Condition â Action (When/Then)
code language-text WHEN Gross Salary > 50000 THEN Show "Additional Deduction"
Best for conditional visibility and progressive disclosure.
-
Action â Condition (Set If/Only if)
code language-text SET Taxable Income = Gross Salary - Deductions IF Deductions are applicable
Best for calculations and data transformations.
-
If â Then â Else (Alternate action)
code language-text IF Income > 50000 THEN Show "High Income" fields ELSE Show "Standard Income" fields
Best for branching logic and mutually exclusive flows.
- Condition: âGross salary exceeds $50,000â
- Primary action: Show âAdditional Deductionâ
- Alternate action: Hide âAdditional Deductionâ
- Result: Users see only the fields that apply to them
Prerequisites
Essential permissions and setup:
- AEM as a Cloud Service: Authoring access with form editing permissions
- Universal Editor: Installed and configured on your environment
- Rule Editor extension: Enabled via Extension Manager
- Form editing permissions: Ability to create and modify form components in Universal Editor
Verification steps:
- Confirm you can access Universal Editor from your AEM Sites console
- Verify you can create and edit form components
- Check that the Rule Editor icon
Required knowledge and skills:
- Universal Editor proficiency: Experience creating forms with text inputs, dropdowns, and basic field properties
- Business logic understanding: Ability to define conditional requirements and validation rules for your specific use case
- Form component familiarity: Knowledge of field types (text, number, dropdown), properties (required, visible, read-only), and form structure
Optional for advanced usage:
- JavaScript fundamentals: Required only for creating custom functions (data types, functions, basic syntax)
- JSON understanding: Helpful for complex data manipulation and API integrations
Assessment questions:
- Can you create a basic form with text inputs and a submit button in Universal Editor?
- Do you understand when fields should be required vs optional in your business context?
- Can you identify which form elements need conditional visibility in your use case?
Important: The Rule Editor extension is not enabled by default in Universal Editor environments.
Activation steps:
- Navigate to the Extension Manager in your AEM environment
- Locate the âRule Editorâ extension in the available extensions list
- Click Enable and confirm the activation
- Wait for the system to refresh (may take 1-2 minutes)
Verification:
- After enabling, the Rule Editor icon appears when you select a form component:
Figure: Rule Editor icon appears when you select form components
To open the Rule Editor:
- Select a form component in Universal Editor.
- Click the Rule Editor icon.
- The Rule Editor opens in a side panel.
Figure: Rule Editor interface for editing component rules
note note |
---|
NOTE |
Throughout this article, âform componentâ and âform objectâ refer to the same elements (for example, inputs, buttons, panels). |
Rule Editor interface overview
Figure: Complete Rule Editor interface with numbered components
-
Component title and rule type: Confirms the selected component and active rule type.
-
Form Objects and Functions panel:
- Form Objects: hierarchical view of fields and containers for referencing in rules
- Functions: built-in math, string, date, and validation helpers
-
Panel toggle: Show/hide the objects and functions panel to increase workspace
-
Visual rule builder: Drag-and-drop, dropdown-driven rule composer
-
Controls: Done (save), Cancel (discard). Always test rules before saving.
When a component already has rules, you can:
- View: See rule summaries and logic
- Edit: Modify conditions and actions
- Reorder: Change execution order (top to bottom)
- Enable/Disable: Toggle rules for testing
- Delete: Remove rules safely
note tip |
---|
TIP |
Put specific rules before general ones. Execution is top-to-bottom. |
Available rule types
Choose the rule type that best matches your intent.
- When: Primary rule for complex conditional behavior (Condition â Action ± Else)
- Hide/Show: Controls visibility based on a condition (progressive disclosure)
- Enable/Disable: Controls whether a field is interactive (for example, disable Submit until required fields are valid)
- Set Value Of: Auto-populate values (for example, dates, totals, copies)
- Clear Value Of: Remove data when conditions change
- Format: Transform display formatting (currency, phone, date) without altering stored values
- Validate: Custom validation logic, including cross-field checks and business rules
- Mathematical Expression: Compute values in real time (totals, tax, ratios)
- Set Focus: Move focus to a specific field (use sparingly)
- Set Property: Modify component properties dynamically (placeholder, options, etc.)
- Submit Form: Programmatically submit the form (only after validations pass)
- Reset Form: Clear and reset to initial state (confirm before use)
- Save Form: Save as draft for later (long forms, multi-session)
- Invoke Service: Call external APIs/services (handle loading and errors)
- Add/Remove Instance: Manage repeatable sections (for example, dependents, addresses)
- Navigate To: Route to other forms/pages (preserve data before navigation)
- Navigate Among Panels: Control wizard step navigation and skipping
- Dispatch Event: Trigger custom events for integrations or analytics
Step-by-step tutorial: Build a smart tax calculator
This example demonstrates conditional visibility and automatic calculations.
Figure: Tax calculation form with intelligent conditional fields
You will build a form that:
- Adapts to user input by showing relevant fields
- Calculates values in real time
- Validates data to improve accuracy
table 0-row-4 1-row-4 2-row-4 3-row-4 4-row-4 | |||
---|---|---|---|
Field Name | Type | Purpose | Behavior |
Gross Salary | Number Input | Userâs annual income | Triggers conditional logic |
Additional Deduction | Number Input | Extra deductions (if eligible) | Visible only when Salary > $50,000 |
Taxable Income | Number Input | Calculated value | Read-only, updates on change |
Tax Payable | Number Input | Calculated value | Read-only, computed at a flat rate |
-
Rule 1: Conditional display
code language-text WHEN Gross Salary > 50,000 THEN Show "Additional Deduction" ELSE Hide "Additional Deduction"
-
Rule 2: Taxable Income calculation
code language-text SET Taxable Income = Gross Salary - Additional Deduction (Only when Additional Deduction applies)
-
Rule 3: Tax Payable calculation
code language-text SET Tax Payable = Taxable Income Ă 10% (Simplified flat rate)
Objective: Build the base form with all fields and initial settings.
-
Open Universal Editor:
- Navigate to AEM Sites console, select your page, click Edit
- Ensure you have the Universal Editor properly configured
-
Add form components in this order:
- Title (H2): âTax Calculation Formâ
- Number Input: âGross Salaryâ (Required: Yes, Placeholder: âEnter annual salaryâ)
- Number Input: âAdditional Deductionâ (Required: No, Placeholder: âEnter additional deductionsâ)
- Number Input: âTaxable Incomeâ (Read-only: Yes)
- Number Input: âTax Payableâ (Read-only: Yes)
- Submit button: âCalculate Taxâ
-
Configure initial field properties:
- Hide âAdditional Deductionâ (set Visible: No in Properties panel)
- Set âTaxable Incomeâ and âTax Payableâ to Read-only: Yes
Figure: Initial form structure with basic components configured
Checkpoint: You should have a form with all required fields where âAdditional Deductionâ is hidden and calculated fields are read-only.
Goal: Show âAdditional Deductionâ field only when Gross Salary exceeds $50,000.
-
Select the Gross Salary field and click the Rule Editor icon
-
Create a new rule:
- Click Create
- Change rule type from âSet Value Ofâ to âWłó±đČÔâ
-
Configure the condition:
- Select âis greater thanâ from the dropdown
- Enter
50000
in the number field
-
Set the Then action:
- Choose âÂÙłóŽÇ·Éâ from the Select Action dropdown
- Drag or select âAdditional Deductionâ field from Form Objects
-
Add the Else action:
- Click âAdd Else Sectionâ
- Choose âHŸ±»ć±đâ from the Select Action dropdown
- Select âAdditional Deductionâ field
-
Save the rule: Click Done
note note |
---|
NOTE |
Alternative approach: You can achieve the same result by creating a Show/Hide rule directly on the âAdditional Deductionâ field instead of a When rule on âGross Salary.â |
Goal: Automatically compute âTaxable Incomeâ and âTax Payableâ based on user input.
Configure Taxable Income calculation:
-
Select âTaxable Incomeâ field and open Rule Editor
-
Create Mathematical Expression:
- Click Create â Select âMathematical Expressionâ
- Build expression: Gross Salary â Additional Deduction
- Drag âGross Salaryâ to first field
- Select âMŸ±ČÔłÜČőâ operator
- Drag âAdditional Deductionâ to second field
-
Save: Click Done
Configure Tax Payable calculation:
-
Select âTax Payableâ field and open Rule Editor
-
Create Mathematical Expression:
- Click Create â Select âMathematical Expressionâ
- Build expression: Taxable Income Ă 10 Ă· 100
- Drag âTaxable Incomeâ to first field
- Select âMultiplied byâ operator
- Enter
10
as number - Click âExtend Expressionâ
- Select âdivided byâ operator
- Enter
100
as number
-
Save: Click Done
Verify your implementation by testing the complete flow:
-
Preview the form: Click the preview mode in Universal Editor
-
Test the conditional logic:
- Enter Gross Salary =
30000
â âAdditional Deductionâ should remain hidden - Enter Gross Salary =
60000
â âAdditional Deductionâ should appear
- Enter Gross Salary =
-
Test calculations:
- With Gross Salary =
60000
, enter Additional Deduction =5000
- Verify Taxable Income =
55000
(60000 - 5000) - Verify Tax Payable =
5500
(55000 Ă 10%)
- With Gross Salary =
Figure: Completed tax calculator with conditional fields and automatic calculations
Success criteria: The form should dynamically show/hide fields and calculate values in real-time as users type.
Advanced: Custom functions
For complex business logic beyond built-in capabilities, you can create custom JavaScript functions that integrate seamlessly with the Rule Editor.
Ideal scenarios for custom functions:
- Complex calculations: Multi-step computations not easily expressed in the Mathematical Expression rule
- Business-specific validations: Custom validation logic specific to your organization or industry
- Data transformations: Format conversions, string manipulations, or data parsing
- External integrations: Calls to internal APIs or third-party services (with limitations)
Benefits of custom functions:
- Reusability: Write once, use across multiple forms and rules
- Maintainability: Centralized logic thatâs easier to update and debug
- Performance: Optimized JavaScript execution compared to complex rule chains
- Flexibility: Handle edge cases and complex scenarios not addressed by standard rules
File location: All custom functions must be defined in /blocks/form/functions.js
in your Edge Delivery Services project.
Development workflow:
-
Function design
- Use descriptive, action-oriented function names
- Define clear parameter types and return values
- Handle edge cases and invalid inputs gracefully
-
Implementation
- Write clean, well-commented JavaScript
- Include input validation and error handling
- Test functions independently before integration
-
Documentation
- Add comprehensive JSDoc comments
- Include usage examples and parameter descriptions
- Document any limitations or dependencies
-
Deployment
- Export functions using named exports
- Deploy to your project repository
- Verify build completion before testing
Example implementation:
code language-javascript |
---|
|
Figure: Adding custom functions to the functions.js file
Integration steps:
-
Add function to project
- Create or edit
/blocks/form/functions.js
in your project - Include your function in the export statement
- Create or edit
-
Deploy and build
- Commit changes to your repository
- Ensure the build process completes successfully
- Allow time for CDN cache updates
-
Access in Rule Editor
- Open Rule Editor for any form component
- Select âFunction Outputâ in the Select Action dropdown
- Choose your custom function from the available functions list
- Configure function parameters using form fields or static values
-
Test thoroughly
- Preview the form to verify function behavior
- Test with various input combinations including edge cases
- Verify performance impact on form loading and interaction
Figure: Selecting and configuring custom functions in the Rule Editor interface
Best practices for function usage:
- Error handling: Always include fallback behavior for function failures
- Performance: Profile functions with realistic data volumes
- Security: Validate all inputs to prevent security vulnerabilities
- Testing: Create test cases covering normal and edge cases
Best practices for rule development
- Minimize rule complexity; split large logic into small, focused rules
- Order rules by frequency (most common first)
- Keep rule sets per component manageable
- Prefer reusable custom functions over duplicating logic
- Provide clear validation and inline feedback
- Avoid jarring visual changes; use show/hide thoughtfully
- Test across devices and layouts
- Test with edge cases and known values
- Verify across browsers
- Document intent behind complex rules, not just mechanics
- Maintain a rule inventory for large forms
- Use consistent naming for components and rules
- Version custom functions and test in non-production environments
Troubleshooting common issues
- Verify component names and references
- Check execution order (top to bottom)
- Validate conditions with known values
- Inspect browser console for blocking errors
- Review operators and grouping (AND/OR)
- Test expression fragments individually
- Confirm data types (numbers vs strings)
- Simplify deeply nested conditions
- Profile custom functions
- Minimize external calls inside rules
- Use specific selectors and references
- Confirm file path:
/blocks/form/functions.js
- Ensure named exports are correct
- Confirm the build includes your changes
- Clear browser cache after deployment
- Validate parameter types and error handling
- Confirm the Rule Editor extension is enabled
- Select a supported component
- Use a supported browser (Chrome, Firefox, Safari)
- Verify you have required permissions
Important limitations
note important |
---|
IMPORTANT |
Custom function constraints: |
|
note warning |
---|
WARNING |
Production considerations: |
|
Summary
The Rule Editor in Universal Editor transforms static forms into intelligent, responsive experiences that adapt to user input in real-time. By leveraging conditional logic, automated calculations, and custom business rules, you can create sophisticated form workflows without writing application code.
Key capabilities youâve learned:
- Conditional logic: Show and hide fields based on user input to create focused, relevant experiences
- Dynamic calculations: Automatically compute values (taxes, totals, rates) as users interact with the form
- Data validation: Implement real-time validation with clear, actionable feedback messages
- Custom functions: Extend capabilities with JavaScript for complex business logic and integrations
- Performance optimization: Apply best practices for maintainable, efficient rule development
Value delivered:
- Enhanced user experience: Reduce cognitive load with progressive disclosure and intelligent form flows
- Reduced errors: Prevent invalid submissions through real-time validation and guided input
- Improved efficiency: Automate calculations and data entry to minimize user effort
- Maintainable solutions: Create reusable, well-documented rules that scale across your organization
Business impact:
Forms become powerful tools for data collection, lead qualification, and user engagement. The Rule Editor enables non-technical authors to implement sophisticated business logic, reducing development costs while improving form completion rates and data quality.
Next steps
Recommended learning path:
- Start with basics: Create simple show/hide rules to understand the core concepts
- Practice with tutorials: Use the tax calculator example as a foundation for your own forms
- Expand gradually: Add mathematical expressions and validation rules as your confidence grows
- Implement custom functions: Develop JavaScript functions for specialized business requirements
- Optimize and scale: Apply performance best practices and maintain rule documentation
Additional resources:
- Universal Editor documentation for broader context
- Extension Manager guide for enabling additional capabilities
- Edge Delivery Services forms for comprehensive form development guidance