Issue using "dependencies" to field that is not displayed by default
General information
- json-editor version: 2.10.1
Expected behavior
As in example below, when using "dependencies " with "defaultProperties" if adding the fieldOne, the depender2 should be automatically added as 'bar' is default selection and if changing fieldOne to 'foo', the depender1 should be displayed to replace depender2.
Actual behavior
Currenlty, when using "dependencies " with "defaultProperties" as in below example if adding the fieldOne, the depender2 is not displayed automatically. Moreover when changing the selection from 'bar' to 'foo', the depender1 is not displayed to replace depender2. But then if the depender1 and depender2 are explicitly manually selected to be displayed, the behavior is correct, meaning if selecting the 'bar' or 'foo', the correct depender is displayed.
Steps to reproduce the behavior
In the schema add "dependencies" to field that is not displayed by default.
Here is a schema example to reproduce the issue :
{
"title": "An object",
"type": "object",
"properties": {
"fieldZero": {
"title": "The default field",
"type": "string"
},
"fieldOne": {
"title": "I should be changed to 'foo'",
"type": "string",
"enum": ["foo","bar"],
"default": "bar"
},
"depender1": {
"title": "I depend on fieldOne to be 'foo'",
"type": "string",
"enum": ["lorem","ipsum"],
"options": {
"dependencies": {
"fieldOne": "foo"
}
}
},
"depender2": {
"title": "I depend on fieldOne to be 'bar'",
"type": "string",
"enum": ["dolor", "sit"],
"options": {
"dependencies": {
"fieldOne": "bar"
}
}
}
},
'defaultProperties': ['fieldZero']
}
if adding the fieldOne, the depender2 is not displayed automatically
From a UX standpoint I understand the issue, but logically, since you're using defaultProperties why should depender1/2 become selected "magically"?
Maybe if-then-else fits better for your usecase?
Thanks for you answer.
if-then-else doesn't suit my needs whereas dependencies match my needs which is as in the example when selecting 'foo' in fieldOne it show depender1 and hide depender2 but when selecting 'bar' in fieldOne it show depender2 and hide depender1.
But I would like to have fieldOne optional, so not displayed by default which I set by removing it from defaultProperties. So in this case if user active the optional fieldOne, the behavior is no more as expected. When selecting 'foo' or "bar', none of depender1/2 are displayed.
Currently the only way would be using show_opt_in, see example.
Also, I do not really see a way to implement the behavior you want, but feel free to submit a PR (with tests) if you have a solution.
@germanbisurgi Do you have any other idea?
@fdeuze We ran into a similar problem, although not 100% the same.
But nonetheless, see this example for some inspiration how to solve the dependeny problem in conjunction with if-then-else and required.