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

Incorrect merge of anyOf with schemaDependencies in arrays

Open skfarhat opened this issue 2 years ago • 2 comments

Prerequisites

What theme are you using?

core

Version

5.x

Current Behavior

schema dependencies when used with oneOf and in array incorrectly merges all properties when the depended on field changes.

Apologies if not clear, it's kind of tough to describe. The reproducer should help

Expected Behavior

I would expect only one of the properties to be shown depending on the number of pets.

Steps To Reproduce

  • Visit Playground link
  • click + to add a person
  • for Do you have any pets, select Yes: One
  • for How old is your pet?*, enter some number, e.g. 5
  • then select Yes: More than one
  • for Do you want to get rid of any?* select either of the options, e.g. true
  • check the formData which now contains both properties
    • Do you want to get rid of any?
    • How old is your pet?
formData =  {
      "Do you have any pets?": "Yes: More than one",
      "Do you want to get rid of any?": true,
      "How old is your pet?": 5
    }

Environment

- OS:
- Node:
- npm:

Playground (all)

Anything else?

No response

skfarhat avatar Jan 27 '23 10:01 skfarhat

@skfarhat This is an interesting bug. While it is true that for simple anyOf/oneOf the unnecessary data gets properly removed (as of beta.18 anyway), but the logic that does that doesn't understand dependencies. As a work around, you can pass true for liveOmit and omitExtraData to get the result you want as you can see in this playground

heath-freenome avatar Jan 27 '23 16:01 heath-freenome

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.

stale[bot] avatar Apr 27 '24 20:04 stale[bot]

This issue was closed because of lack of recent activity. Reopen if you still need assistance.

stale[bot] avatar May 28 '24 00:05 stale[bot]