react-jsonschema-form
react-jsonschema-form copied to clipboard
Combination of `anyOf`/`allOf` does not retain the correct option defaults
Prerequisites
- [x] I have read the documentation;
- [x] In the case of a bug report, I understand that providing a SSCCE example is tremendously useful to the maintainers.
- [x] Ideally, I'm providing a sample JSFiddle or a shared playground link demonstrating the issue.
Description
When having a combination of anyOf/allOf, the generated default option for anyOf is not retained correctly from the form data.
See this link in CodeSandbox for an example.
Steps to Reproduce
- Open the example.
- Choose a variable and change it from
BaztoBax. - Change tabs from
FormtoJSON, and back again fromJSONtoForm.
Expected behavior
The option for a variable selected is retained between the tab changes.
Actual behavior
The option for a variable selected is always changed to the first option (in this case Baz).
Version
2.4.0
Additional details:
I tried to debug this issue, and there are certain points which might be the cause, but please correct me if I have misunderstood something here:
- In
core/src/util.js:224,getMatchingOptionis being passedformDataasundefined, shouldn’t it just pass theformDataas it is? - In
core/src/util.js:1179, shouldn’t theoptionbe resolved first withresolveSchema(option, schema, formData)in order to have all$ref's resolved before performing validation atcore/src/util.js:1222andcore/src/util.js:1225?
Related issues/PRs:
PRs:
https://github.com/rjsf-team/react-jsonschema-form/pull/1564
I reproduced this issue using only allOf (without combining it with anyOf): Playground.
I copied the example from the official Json Schema documentation but added defaults.
Expected: Form should show defaults for both addresses. Actual: Form only shows defaults for the address not using allOf.
This issue has been automatically marked as possibly close because it has not had recent activity. It will be closed if no further activity occurs. Please leave a comment if this is still an issue for you. Thank you.
This issue was closed because of lack of recent activity. Reopen if you still need assistance.