json-editor
json-editor copied to clipboard
[Question] Hide/show property if another optional property is NOT set.
Hi! Is it possible to have a dependency rule that shows/hide a property depending if another (optional) field is NOT set ?
(non working) Example https://is.gd/zs8a1X
{
"type": "object",
"title": "test",
"properties": {
"item1": {
"type": "object",
"required": false,
"properties": {
"prop1": {
"type":"string",
"title": "Some Field"
}
}
},
"item2": {
"type": "string",
"required": false,
"options": {
"dependencies": {
"item1": null // ===> item1 (not required) should not be 'something' or enabled via the checkbox.
}
}
}
}
}
Thanks
There is indeed:
{
"type": "object",
"title": "test",
"properties": {
"item1": {
"type": "object",
"required": false,
"properties": {
"prop1": {
"type":"string",
"title": "Some Field"
}
}
},
"item2": {
"type": "string",
"options": {
"dependencies": {
"item1": {
"prop1": ""
}
}
}
}
}
}
Explanation: JSONEditor uses JSON.stringify() on the values that should be compared to. In your case you are checking for undefined and JSON.stringify("") is equal to undefined.
Thanks, thats clever! Unfortunately it doesn't work with the checkbox toggle, check https://is.gd/pGuuIR
I am working on a solution for that. Will post a PR as soon as possible.