rjsf-team / react-jsonschema-form

A React component for building Web forms from JSON Schema.
https://rjsf-team.github.io/react-jsonschema-form/
Apache License 2.0
14.35k stars 2.19k forks source link

Unexpected behavior when conditionally including fields with if-then-else #4362

Open donalddalton opened 1 week ago

donalddalton commented 1 week ago

Prerequisites

What theme are you using?

mui

Version

5.x

Current Behavior

I have a schema with a top-level boolean property (called parent) which is used to conditionally add another property with a default value (called child) via an if-then-else statement. RJSF correctly shows/hides child based on the value of parent, however, the default value of child is always included in form data.

Similarly, in the case where child does not have a default and you:

  1. set parent=true
  2. input a value for child
  3. set parent=false

The child field is hidden in the form but the value is still included in form data.

Expected Behavior

That the value of child is conditionally included/excluded from form data.

Steps To Reproduce

Check out this playground example recapitulating the scenario above. Notice how the value of child is included in form data regardless of the value of parent.

Environment

- OS: Ubuntu
- Node: 18

Anything else?

No response

heath-freenome commented 5 days ago

@donalddalton Have you tried using the omitExtraData and liveOmit features? This playground show it works