react-jsonschema-form icon indicating copy to clipboard operation
react-jsonschema-form copied to clipboard

Fix oneOf schema not working when omitExtraData and liveOmit is set.

Open knjoeyn opened this issue 3 years ago • 5 comments

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
  • [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.

knjoeyn avatar Sep 14 '21 22:09 knjoeyn

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.

FareedSokkar avatar Sep 27 '21 06:09 FareedSokkar

Hi @FareedSokkar did you guys just fix it locally in your own cloned code to make things work?

knjoeyn avatar Sep 29 '21 17:09 knjoeyn

@knjoeyn yes, we cloned from the main branch then applied our changes and tested locally.

FareedSokkar avatar Oct 03 '21 06:10 FareedSokkar

Hi @knjoeyn, Any updates?

FareedSokkar avatar Oct 12 '21 08:10 FareedSokkar

@knjoeyn With the utils functions being refactored into its own package @rjsf/utils in v5, this code needs to be refactored there

heath-freenome avatar Sep 07 '22 17:09 heath-freenome

Reimplemented in #3399, closing

heath-freenome avatar Jan 25 '23 18:01 heath-freenome