Skip to main content
Conditional logic allows you to show or hide fields and pages based on the values of other fields. This enables dynamic forms that adapt based on user input, creating a more intuitive and streamlined user experience.

Overview

Conditional logic in JoyDoc uses a rule-based system where you define conditions that determine when fields or pages should be shown or hidden. The logic is evaluated in real-time as users interact with the form, automatically showing or hiding elements based on the current field values.

How Conditional Logic Works

Conditional logic consists of three main components:
  1. Action - What should happen when conditions are met (show or hide)
  2. Evaluation - How conditions should be combined (and or or)
  3. Conditions - The actual rules to check (field values, comparisons, etc.)

Logic Structure

Basic Structure

Actions

The action property determines what happens when the conditions are met:
  • show - Show the field/page when conditions match (field/page starts hidden)
  • hide - Hide the field/page when conditions match (field/page starts visible)

Evaluation Types

The eval property determines how multiple conditions are combined:
  • and - All conditions must be true for the action to trigger
  • or - Any condition must be true for the action to trigger

Condition Operators

The condition property supports different comparison operators depending on the field type:

Text and Textarea Fields

  • *= - is filled - Field has any value
  • null= - is empty - Field is empty or null
  • = - is - Field value equals the specified value
  • != - is not - Field value does not equal the specified value
  • ?= - contains - Field value contains the specified substring (case-insensitive)

Number Fields

  • *= - is filled - Field has a numeric value
  • null= - is empty - Field is empty or null
  • = - is - Field value equals the specified number
  • != - is not - Field value does not equal the specified number
  • > - is greater than - Field value is greater than the specified number
  • < - is less than - Field value is less than the specified number
  • *= - is filled - Field has at least one option selected
  • null= - is empty - Field has no options selected
  • = - is - Field value equals the specified option
  • != - is not - Field value does not equal the specified option

Field-Level Conditional Logic

Fields can have conditional logic applied to show or hide themselves based on other field values.

Example: Show Field When Another Field Has Value

Example: Hide Field Based on Number Comparison

Example: Multiple Conditions with AND

Example: Multiple Conditions with OR

Example: Text Contains Condition

Page-Level Conditional Logic

Pages can also have conditional logic applied to show or hide entire pages based on field values.

Example: Show Page When Condition Met

Example: Hide Page Based on Number Range

Supported Field Types

Conditional logic can reference the following field types in conditions:
  • Text (text) - Supports all text operators
  • Textarea (textarea) - Supports all text operators
  • Number (number) - Supports all number operators
  • Dropdown (dropdown) - Supports dropdown operators
  • MultiSelect (multiSelect) - Supports dropdown operators
Note: Fields used in conditions must be on a different page than the field/page being controlled (you cannot reference a field from the same page).

Complete Example

Best Practices

  1. Start with Hidden State - When using show action, set hidden: true initially so the field/page starts hidden
  2. Use Specific Field IDs - Always reference fields by their _id property
  3. Cross-Page References - Conditions must reference fields from different pages
  4. Test Edge Cases - Test with empty values, null values, and boundary conditions
  5. Keep Conditions Simple - Complex logic with many conditions can be harder to maintain
  6. Use AND for Required Conditions - Use and when all conditions must be met
  7. Use OR for Optional Conditions - Use or when any condition can trigger the action

Common Patterns

Pattern 1: Show/Hide Based on Dropdown Selection

Pattern 2: Show/Hide Based on Text Contains

Pattern 3: Show/Hide Based on Number Range

Pattern 4: Multiple Required Conditions

Pattern 5: Any Condition Can Trigger

Troubleshooting

Field Not Showing/Hiding

  1. Check hidden property - Ensure hidden: true when using show action
  2. Verify field references - Ensure field IDs in conditions match actual field IDs
  3. Check page references - Ensure page IDs are correct
  4. Verify condition syntax - Check that condition operators match field types
  5. Test condition values - Ensure comparison values match actual field values

Condition Not Working

  1. Field type compatibility - Verify the condition operator is supported for the field type
  2. Value matching - For dropdown/multiSelect, ensure the value matches exactly
  3. Empty vs null - Check if field is empty (null=) or filled (*=)
  4. Case sensitivity - Text contains (?=) is case-insensitive, but equals (=) is case-sensitive

Bonus Tip: