Conditional Fields

A schema can use if to test a condition against the current value. When the condition matches, then applies; when it doesn't, else applies instead. Either then or else alone is enough — only if itself is required.

Activation Conditions

  • Schema has an if keyword — then and else are both optional and evaluated independently.

How branch switching works

Jedison builds one editor per matching branch and swaps which one is shown as the watched fields change. Switching branches keeps each branch's own field values remembered rather than wiping them, so flipping back and forth doesn't lose data.

Example

{
  "title": "Conditional Fields",
  "type": "object",
  "properties": {
    "subscribe": {
      "type": "boolean",
      "title": "Subscribe to the newsletter?"
    }
  },
  "if": {
    "properties": {
      "subscribe": {
        "const": true
      }
    }
  },
  "then": {
    "properties": {
      "email": {
        "type": "string",
        "format": "email",
        "title": "Email address"
      }
    },
    "required": [
      "email"
    ]
  }
}

Chaining Conditions (else-if)

Nesting another if/then/else inside an else block chains conditions together, like an else-if ladder.

Example

{
  "title": "Vehicle",
  "type": "object",
  "properties": {
    "vehicleType": {
      "type": "string",
      "enum": [
        "car",
        "motorcycle",
        "bicycle",
        "other"
      ],
      "default": "motorcycle"
    }
  },
  "if": {
    "properties": {
      "vehicleType": {
        "const": "car"
      }
    }
  },
  "then": {
    "properties": {
      "numDoors": {
        "type": "integer"
      }
    }
  },
  "else": {
    "if": {
      "properties": {
        "vehicleType": {
          "const": "motorcycle"
        }
      }
    },
    "then": {
      "properties": {
        "numWheels": {
          "type": "integer"
        }
      }
    },
    "else": {
      "if": {
        "properties": {
          "vehicleType": {
            "const": "bicycle"
          }
        }
      },
      "then": {
        "properties": {
          "numPedals": {
            "type": "integer"
          }
        }
      },
      "else": {
        "properties": {
          "make": {
            "type": "string"
          },
          "model": {
            "type": "string"
          }
        }
      }
    }
  }
}