Rule Editor for Dynamic Forms in Universal Editor
The Rule Editor allows authors to turn static forms into responsive, intelligent experiences鈥攚ithout 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鈥檒l 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: 鈥淚ncome > 50,000,鈥 鈥淐overage = 鈥榊es鈥,鈥 鈥淔ield 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: 鈥淕ross salary exceeds $50,000鈥
- Primary action: Show 鈥淎dditional Deduction鈥
- Alternate action: Hide 鈥淎dditional 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 鈥淩ule 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, 鈥渇orm component鈥 and 鈥渇orm 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鈥檚 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): 鈥淭ax Calculation Form鈥
- Number Input: 鈥淕ross Salary鈥 (Required: Yes, Placeholder: 鈥淓nter annual salary鈥)
- Number Input: 鈥淎dditional Deduction鈥 (Required: No, Placeholder: 鈥淓nter additional deductions鈥)
- Number Input: 鈥淭axable Income鈥 (Read-only: Yes)
- Number Input: 鈥淭ax Payable鈥 (Read-only: Yes)
- Submit button: 鈥淐alculate Tax鈥
-
Configure initial field properties:
- Hide 鈥淎dditional Deduction鈥 (set Visible: No in Properties panel)
- Set 鈥淭axable Income鈥 and 鈥淭ax Payable鈥 to Read-only: Yes
Figure: Initial form structure with basic components configured
Checkpoint: You should have a form with all required fields where 鈥淎dditional Deduction鈥 is hidden and calculated fields are read-only.
Goal: Show 鈥淎dditional 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 鈥淪et Value Of鈥 to 鈥淲丑别苍鈥
-
Configure the condition:
- Select 鈥渋s greater than鈥 from the dropdown
- Enter
50000
in the number field
-
Set the Then action:
- Choose 鈥沦丑辞飞鈥 from the Select Action dropdown
- Drag or select 鈥淎dditional Deduction鈥 field from Form Objects
-
Add the Else action:
- Click 鈥淎dd Else Section鈥
- Choose 鈥淗颈诲别鈥 from the Select Action dropdown
- Select 鈥淎dditional 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 鈥淎dditional Deduction鈥 field instead of a When rule on 鈥淕ross Salary.鈥 |
Goal: Automatically compute 鈥淭axable Income鈥 and 鈥淭ax Payable鈥 based on user input.
Configure Taxable Income calculation:
-
Select 鈥淭axable Income鈥 field and open Rule Editor
-
Create Mathematical Expression:
- Click Create 鈫 Select 鈥淢athematical Expression鈥
- Build expression: Gross Salary 鈭 Additional Deduction
- Drag 鈥淕ross Salary鈥 to first field
- Select 鈥淢颈苍耻蝉鈥 operator
- Drag 鈥淎dditional Deduction鈥 to second field
-
Save: Click Done
Configure Tax Payable calculation:
-
Select 鈥淭ax Payable鈥 field and open Rule Editor
-
Create Mathematical Expression:
- Click Create 鈫 Select 鈥淢athematical Expression鈥
- Build expression: Taxable Income 脳 10 梅 100
- Drag 鈥淭axable Income鈥 to first field
- Select 鈥淢ultiplied by鈥 operator
- Enter
10
as number - Click 鈥淓xtend Expression鈥
- Select 鈥渄ivided 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
鈫 鈥淎dditional Deduction鈥 should remain hidden - Enter Gross Salary =
60000
鈫 鈥淎dditional 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鈥檚 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 鈥淔unction 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
Static Imports for Custom Functions
The Universal Editor鈥檚 Rule Editor supports static imports, enabling you to organize reusable logic across multiple files and forms. Instead of keeping all custom functions in a single file (/blocks/form/functions.js?lang=en), you can import functions from other modules.
For example: Importing Functions from an External File
Consider the following folder structure:
form
鈹 commonLib
鈹 鈹 functions.js
鈹 rules
鈹 鈹 _form.json
鈹 form.js
鈹 functions.js
You can import functions from commonLib/functions.js
into your main functions.js
file as shown below:
`import {days} from './commonLib/functions';
/**
* Get Full Name
* @name getFullName Concats first name and last name
* @param {string} firstname in String format
* @param {string} lastname in String format
* @return {string}
*/
function getFullName(firstname, lastname) {
return `${firstname} ${lastname}`.trim();
}
// Export multiple functions for use in Rule Editor
export { getFullName, days};
Organizing Custom Functions Across Different Forms
You can create different sets of functions in separate files or folders and export them as required:
-
If you want certain functions to be available only in specific forms, you can provide the path to the functions file in the form configuration.
-
If the textbox for the path is left blank, the Rule Editor defaults to loading functions from
/blocks/form/functions.js
In the screenshot above, the path of the custom function is added in the Custom Function Path textbox. The custom functions for this form are loaded from the specified file (cc_function.js
).
This allows flexibility by sharing functions across multiple forms or keeping them isolated per form.
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鈥檝e 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