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:-
Action - What should happen when conditions are met (
showorhide) -
Evaluation - How conditions should be combined (
andoror) - Conditions - The actual rules to check (field values, comparisons, etc.)
Logic Structure
Basic Structure
Actions
Theaction 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
Theeval 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
Thecondition 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
Dropdown and MultiSelect Fields
-
*=- 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
Complete Example
Best Practices
-
Start with Hidden State - When using
showaction, sethidden: trueinitially so the field/page starts hidden -
Use Specific Field IDs - Always reference fields by their
_idproperty - Cross-Page References - Conditions must reference fields from different pages
- Test Edge Cases - Test with empty values, null values, and boundary conditions
- Keep Conditions Simple - Complex logic with many conditions can be harder to maintain
-
Use AND for Required Conditions - Use
andwhen all conditions must be met -
Use OR for Optional Conditions - Use
orwhen 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
-
Check
hiddenproperty - Ensurehidden: truewhen usingshowaction - Verify field references - Ensure field IDs in conditions match actual field IDs
- Check page references - Ensure page IDs are correct
- Verify condition syntax - Check that condition operators match field types
- Test condition values - Ensure comparison values match actual field values
Condition Not Working
- Field type compatibility - Verify the condition operator is supported for the field type
- Value matching - For dropdown/multiSelect, ensure the value matches exactly
-
Empty vs null - Check if field is empty (
null=) or filled (*=) -
Case sensitivity - Text contains (
?=) is case-insensitive, but equals (=) is case-sensitive
Bonus Tip:
- Checkout the github repo here - https://github.com/joyfill/conditional-logic