react-jsonschema-form
react-jsonschema-form copied to clipboard
Fix oneOf schema not working when omitExtraData and liveOmit is set.
Reasons for making this change
For schema with oneOf array, setting omitExtraData and liveOmit would cause formData to be clear out on input change. This PR fixes this issue by adding code to hand oneOf schema inside toPathSchema function.
fixes #2262 https://github.com/rjsf-team/react-jsonschema-form/issues/2262
Checklist
- [ ] I'm updating documentation
- [ ] I've checked the rendering of the Markdown text I've added
- [x] I'm adding or updating code
- [x] I've added and/or updated tests
- [x] I've updated docs if needed
- [ ] I'm adding a new feature
- [ ] I've updated the playground with an example use of the feature
@epicfaace @agustin107 this is blocking issue for our company's project, if you can take a quick look, it would be greatly appreciated.
Hello @knjoeyn , I am a developer that is using the RJSF for fast form creation when my team and I faced the oneOf issue as well, and we figured out the way to fix it (both oneOf and anyOf) I am commenting here because I wasn't able to make any commits. and based on the code you committed I saw similarity with few tweaks.
In the utils.js files: Inside the toPathSchema function, right before the return statement add the following (the two blocks are similar but because the schema may contain both 'oneOf' & 'anyOf' in the same level it shouldn't be one case).
if(schema.hasOwnProperty("oneOf")){ let option=getMatchingOption(formData,schema.oneOf,rootSchema); console.log("oneOf: ",option) let returnVal=toPathSchema( schema.oneOf[option],
oneOf.${option}, rootSchema, formData ); for (const property in returnVal) { if(property!='$name'){ pathSchema[property] = returnVal[property]; } } } if(schema.hasOwnProperty("anyOf")){ let option=getMatchingOption(formData,schema.anyOf,rootSchema); let returnVal = toPathSchema( schema.anyOf[option],
anyOf.${option}, rootSchema, formData ); for (const property in returnVal) { if(property!='$name'){ pathSchema[property] = returnVal[property]; } } }
Attached code file: fix1.txt
Thank you so much.
Hi @FareedSokkar did you guys just fix it locally in your own cloned code to make things work?
@knjoeyn yes, we cloned from the main branch then applied our changes and tested locally.
Hi @knjoeyn, Any updates?
@knjoeyn With the utils functions being refactored into its own package @rjsf/utils
in v5, this code needs to be refactored there
Reimplemented in #3399, closing