ReadOnly
JSON Forms allows to enable and disable any input, either programmatically, via JSON Schema or the UI schema.
#
Form WideThe whole form can be disabled by specifying the readonly
flag on the JsonForms
component itself.
This will disable all elements of this form.
This flag is also supported by the Angular and Vue bindings.
- Demo
- Schema
- UI Schema
- Data
schema.json
{"properties": {"firstName": {"type": "string"},"lastName": {"type": "string"}}}
uischema.json
{"type": "VerticalLayout","elements": [{"type": "Control","scope": "#/properties/firstName"},{"type": "Control","scope": "#/properties/lastName"}]}
{"firstName": "Max","lastName": "Mustermann"}
#
Schema based#
UI Schema optionThe option readonly: true
can be set on any element in the UI schema:
- Demo
- Schema
- UI Schema
- Data
schema.json
{"properties": {"firstName": {"type": "string"},"lastName": {"type": "string"}}}
uischema.json
{"type": "VerticalLayout","elements": [{"type": "Control","scope": "#/properties/firstName","options": {"readOnly": true}},{"type": "Control","scope": "#/properties/lastName"}]}
{"firstName": "Max","lastName": "Mustermann"}
#
JSON SchemaTo disable an input via JSON Schema, specify readOnly: true
:
Note: JSON Forms will ignore readonly
within JSON Schemas as only readOnly
is part of the specification.
- Demo
- Schema
- UI Schema
- Data
schema.json
{"properties": {"firstName": {"type": "string","readOnly": true},"lastName": {"type": "string"}}}
uischema.json
{"type": "VerticalLayout","elements": [{"type": "Control","scope": "#/properties/firstName"},{"type": "Control","scope": "#/properties/lastName"}]}
{"firstName": "Max","lastName": "Mustermann"}
#
RuleAny UI schema element can be enabled or disabled dynamically via our rule support.
- Demo
- Schema
- UI Schema
- Data
schema.json
{"properties": {"firstName": {"type": "string"},"lastName": {"type": "string"}}}
uischema.json
{"type": "VerticalLayout","elements": [{"type": "Control","scope": "#/properties/firstName","rule": {"effect": "DISABLE","condition": {"scope": "#","schema": {}}}},{"type": "Control","scope": "#/properties/lastName"}]}
{"firstName": "Max","lastName": "Mustermann"}
#
Evaluation orderJSON Forms determines the enabled
status for each UI schema element based on the following order
- When the form wide
readonly
is specified, all inputs will be disabled. - If an
ENABLE
orDISABLE
rule exists, the UI schema element will be rendered accordingly. - If the UI schema
readonly
option is set, the UI schema element will be rendered accordingly. - If the JSON Schema
readOnly: true
attribute is specified, the UI schema element will be disabled. - If none of the above apply, the UI schema element will be enabled or disabled based on its parent.