Conditional Logic

Show, hide, and modify fields based on user input using conditional logic.

Overview

Conditional logic allows you to create dynamic forms that respond to user input. Show or hide fields, skip pages, or change validation rules based on answers.

Basic Conditions

Show/Hide Fields

Show a field only when a condition is met:

json
{
  "type": "text",
  "name": "otherReason",
  "label": "Please specify",
  "conditions": {
    "show": {
      "field": "reason",
      "operator": "equals",
      "value": "other"
    }
  }
}

Result:

  • "Other reason" field only appears when user selects "Other" in the reason dropdown

Available Operators

OperatorDescriptionExample
equalsExact matchvalue === "yes"
notEqualsNot equalvalue !== "no"
containsContains substring"hello world".includes("hello")
notContainsDoesn't contain
startsWithStarts with
endsWithEnds with
isEmptyField is empty
isNotEmptyField has value
greaterThanNumber comparisonvalue > 100
lessThanNumber comparisonvalue < 50
greaterOrEqualNumber comparisonvalue >= 18
lessOrEqualNumber comparisonvalue <= 100
betweenRange checkvalue >= 10 && value <= 20
inIn list of values["a", "b"].includes(value)
notInNot in list
matchesRegex match

Multiple Conditions

AND Logic

All conditions must be true:

json
{
  "conditions": {
    "show": {
      "logic": "and",
      "rules": [
        { "field": "country", "operator": "equals", "value": "US" },
        { "field": "age", "operator": "greaterOrEqual", "value": 18 }
      ]
    }
  }
}

OR Logic

Any condition can be true:

json
{
  "conditions": {
    "show": {
      "logic": "or",
      "rules": [
        { "field": "plan", "operator": "equals", "value": "pro" },
        { "field": "plan", "operator": "equals", "value": "enterprise" }
      ]
    }
  }
}

Nested Logic

Combine AND and OR:

json
{
  "conditions": {
    "show": {
      "logic": "and",
      "rules": [
        { "field": "isEmployee", "operator": "equals", "value": true },
        {
          "logic": "or",
          "rules": [
            { "field": "department", "operator": "equals", "value": "engineering" },
            { "field": "department", "operator": "equals", "value": "product" }
          ]
        }
      ]
    }
  }
}

Conditional Actions

Show/Hide

json
{
  "conditions": {
    "show": { "field": "subscribe", "operator": "equals", "value": true }
  }
}

Enable/Disable

json
{
  "conditions": {
    "enable": { "field": "agreeTerms", "operator": "equals", "value": true }
  }
}

Required/Optional

json
{
  "conditions": {
    "require": { "field": "hasCompany", "operator": "equals", "value": true }
  }
}

Set Value

json
{
  "conditions": {
    "setValue": {
      "when": { "field": "country", "operator": "equals", "value": "US" },
      "value": "+1"
    }
  }
}

Change Options

Dynamically change dropdown options:

json
{
  "type": "dropdown",
  "name": "state",
  "label": "State/Province",
  "conditions": {
    "setOptions": [
      {
        "when": { "field": "country", "operator": "equals", "value": "US" },
        "options": [
          { "value": "CA", "label": "California" },
          { "value": "NY", "label": "New York" }
        ]
      },
      {
        "when": { "field": "country", "operator": "equals", "value": "CA" },
        "options": [
          { "value": "ON", "label": "Ontario" },
          { "value": "BC", "label": "British Columbia" }
        ]
      }
    ]
  }
}

Page/Section Conditions

Show/Hide Sections

json
{
  "type": "section",
  "title": "Business Information",
  "conditions": {
    "show": { "field": "accountType", "operator": "equals", "value": "business" }
  },
  "fields": ["companyName", "taxId", "industry"]
}

Skip Pages

In multi-step forms:

json
{
  "pages": [
    {
      "title": "Account Type",
      "fields": ["accountType"]
    },
    {
      "title": "Personal Info",
      "fields": ["name", "email"],
      "conditions": {
        "show": { "field": "accountType", "operator": "equals", "value": "personal" }
      }
    },
    {
      "title": "Business Info",
      "fields": ["companyName", "taxId"],
      "conditions": {
        "show": { "field": "accountType", "operator": "equals", "value": "business" }
      }
    },
    {
      "title": "Review",
      "fields": ["summary"]
    }
  ]
}

Field References

Referencing Other Fields

Use field names in conditions:

json
{
  "conditions": {
    "show": {
      "field": "wantNewsletter",
      "operator": "equals",
      "value": true
    }
  }
}

Referencing Array Fields

For checkbox groups or multi-select:

json
{
  "conditions": {
    "show": {
      "field": "interests",
      "operator": "contains",
      "value": "technology"
    }
  }
}

Referencing Nested Fields

For complex field structures:

json
{
  "conditions": {
    "show": {
      "field": "address.country",
      "operator": "equals",
      "value": "US"
    }
  }
}

Real-World Examples

Dynamic Product Form

json
{
  "fields": [
    {
      "type": "dropdown",
      "name": "productType",
      "label": "Product Type",
      "options": [
        { "value": "physical", "label": "Physical Product" },
        { "value": "digital", "label": "Digital Product" },
        { "value": "service", "label": "Service" }
      ]
    },
    {
      "type": "text",
      "name": "weight",
      "label": "Weight (kg)",
      "conditions": {
        "show": { "field": "productType", "operator": "equals", "value": "physical" }
      }
    },
    {
      "type": "text",
      "name": "downloadUrl",
      "label": "Download URL",
      "conditions": {
        "show": { "field": "productType", "operator": "equals", "value": "digital" }
      }
    },
    {
      "type": "number",
      "name": "duration",
      "label": "Service Duration (hours)",
      "conditions": {
        "show": { "field": "productType", "operator": "equals", "value": "service" }
      }
    }
  ]
}

Conditional Pricing

json
{
  "fields": [
    {
      "type": "dropdown",
      "name": "plan",
      "label": "Select Plan",
      "options": [
        { "value": "basic", "label": "Basic - $9/mo" },
        { "value": "pro", "label": "Pro - $29/mo" },
        { "value": "enterprise", "label": "Enterprise - Custom" }
      ]
    },
    {
      "type": "number",
      "name": "seats",
      "label": "Number of Seats",
      "conditions": {
        "show": { "field": "plan", "operator": "in", "value": ["pro", "enterprise"] }
      }
    },
    {
      "type": "textarea",
      "name": "requirements",
      "label": "Special Requirements",
      "conditions": {
        "show": { "field": "plan", "operator": "equals", "value": "enterprise" },
        "require": { "field": "plan", "operator": "equals", "value": "enterprise" }
      }
    }
  ]
}

Age-Based Content

json
{
  "fields": [
    {
      "type": "number",
      "name": "age",
      "label": "Your Age",
      "min": 1,
      "max": 120
    },
    {
      "type": "section",
      "title": "Parental Consent",
      "conditions": {
        "show": { "field": "age", "operator": "lessThan", "value": 18 }
      },
      "fields": ["parentName", "parentEmail", "parentConsent"]
    },
    {
      "type": "checkbox",
      "name": "alcoholPreference",
      "label": "Include alcohol options",
      "conditions": {
        "show": { "field": "age", "operator": "greaterOrEqual", "value": 21 }
      }
    }
  ]
}

UI Configuration

Show/Hide Animation

json
{
  "conditionalLogic": {
    "animation": "fade",
    "duration": 200
  }
}
AnimationDescription
noneInstant show/hide
fadeFade in/out
slideSlide down/up
expandExpand/collapse

Best Practices

  1. Keep it simple - Avoid overly complex conditions
  2. Test thoroughly - Check all condition paths
  3. Clear labels - Make it obvious why fields appear
  4. Logical flow - Conditions should make sense to users
  5. Mobile testing - Ensure conditions work on all devices
  6. Default states - Set sensible defaults for conditional fields