Skip to content

Support applying subschemas conditionally #40

@mfulton26

Description

@mfulton26

Draft 7 of JSON Schema addes Keywords for Applying Subschemas Conditionally.

It would be amazing to add support for if/then/else to liform-react. e.g.:

schema:

{
    "properties": { "power": { "type": "integer" } },
    "if": { "properties": { "power": { "const": 9000 } } },
    "then": { "properties": { "disbelief": { "type": "boolean" } } },
    "else": { "properties": { "confidence": { "type": "string" } } }
}

data 1:

{ "power": 12 }

form 1:

<form>
    <label for="field-power">power</label>
    <input id="field-power" type="number" step="1"/>
    <label for="field-disbelief">disbelief</label>
    <input id="field-disbelief" type="checkbox"/>
</form>

data 2:

{ "power": 42000 }

form 1:

<form>
    <label for="field-power">power</label>
    <input id="field-power" type="number" step="1"/>
    <label for="field-confidence">confidence</label>
    <input id="field-confidence" type="text"/>
</form>

Basically, if the if schema is valid then the then schema is applied, otherwise the else schema is applied (if else is defined).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions