Conditional Fields & Sections

Add a condition to any field, section, or signer slot to show or hide it based on earlier answers. When there's no condition, the element is always visible.

The condition model

{
  "condition": {
    "match": "all",
    "rules": [
      { "field": "favorite_color", "operator": "EQUALS", "value": "other" }
    ]
  }
}
PropertyTypeDefaultDescription
condition.match"all" | "any""all""all" = every rule must pass (AND). "any" = at least one (OR).
condition.rulesarrayOne or more rules to evaluate.

Each rule:

PropertyTypeRequiredDescription
fieldstringyesThe name of another field. Must appear before this element in form order.
operatorstringyesOne of the operators below.
valuestring | number | nulldependsRequired for every operator except IS_EMPTY and IS_NOT_EMPTY.

Operators

Which operators a rule can use depends on the referenced field's type:

OperatorMeaningField types
EQUALSMatches exactly. For CHOICE: the option is among the selected values.TEXT, NUMBER, DATE, DATETIME, CHOICE, EMAIL, PHONE
NOT_EQUALSThe opposite of EQUALS.TEXT, NUMBER, DATE, DATETIME, CHOICE, EMAIL, PHONE
GREATER_THANGreater-than comparison (numeric or date).NUMBER, DATE, DATETIME
LESS_THANLess-than comparison (numeric or date).NUMBER, DATE, DATETIME
IS_EMPTYThe field has no answer.TEXT, NUMBER, DATE, DATETIME, CHOICE, EMAIL, PHONE, NIN, BUSINESS_ID, FILE
IS_NOT_EMPTYThe field has any answer.TEXT, NUMBER, DATE, DATETIME, CHOICE, EMAIL, PHONE, NIN, BUSINESS_ID, FILE

Rules

  • A rule's field must reference a field that appears before the conditional element in form order. Field conditions can reference earlier fields in the same or a prior section; section conditions can only reference fields from prior sections.
  • Conditions chain: if B depends on A and C depends on B, hiding A cascades to both.
  • required: true with a condition means "required when visible". While hidden, the requirement is ignored.

Example: show a field when "Other" is selected

{
  "sections": [
    {
      "title": "Your Preferences",
      "fields": [
        {
          "type": "CHOICE", "name": "favorite_color", "label": "Favorite color", "required": true, "layout": "RADIO",
          "options": [
            { "label": "Red",   "value": "red" },
            { "label": "Blue",  "value": "blue" },
            { "label": "Other", "value": "other" }
          ]
        },
        {
          "type": "TEXT", "name": "color_specify", "label": "Please specify", "required": true,
          "condition": { "rules": [ { "field": "favorite_color", "operator": "EQUALS", "value": "other" } ] }
        }
      ]
    }
  ]
}

color_specify appears only when "Other" is selected, and is required when visible.

Example: a conditional section

A whole section (and its fields) can be hidden based on a field in a prior section:

{
  "sections": [
    {
      "title": "General",
      "fields": [
        {
          "type": "CHOICE", "name": "has_allergies", "label": "Do you have any allergies?", "required": true, "layout": "RADIO",
          "options": [ { "label": "Yes", "value": "yes" }, { "label": "No", "value": "no" } ]
        }
      ]
    },
    {
      "title": "Allergy Details",
      "condition": { "rules": [ { "field": "has_allergies", "operator": "EQUALS", "value": "yes" } ] },
      "fields": [
        { "type": "TEXT", "label": "Please describe your allergies", "required": true, "multiline": true }
      ]
    }
  ]
}

Signer slots inside additionalSignersConfig accept a condition in the same way.