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
13.76k stars 2.16k forks source link

Issue with omit extra data and live omit not working onSubmit #4187

Open AayushB opened 3 weeks ago

AayushB commented 3 weeks ago

Prerequisites

What theme are you using?

bootstrap-4

What is your question?

I'm encountering an issue with the React JSON Form library where omit and liveOmit functionality seems to be working only on onChange but not on onSubmit, particularly when the user proceeds to submit the form without making any changes. When I use omit or liveOmit to exclude certain fields from the form submission, it behaves as expected during user interaction (onChange), but the omitted fields still get submitted when the form is submitted (onSubmit) without any user modifications.

Is there a known workaround or configuration setting to ensure that omitted fields are also excluded from the final form submission (onSubmit) in cases where the user hasn't made any changes? Alternatively, is there a recommended approach to achieve omitting fields specifically on form submission?

Here's how you can replicate the issue in react playground:

  1. Navigate to the React JSON Form playground.
  2. In the JSON schema, add a field called "foo" with a default value of "bar".
  3. Check the "Omit extra data" and "Live omit" options.
  4. Observe that the "foo" field is included in the form.
  5. Without making any changes to the form fields, click the "Submit" button.
  6. Notice that despite the "Omit extra data" and "Live omit" options being checked, the "foo" field is still included in the submitted data.
  7. If you now make any changes to the form, foo should get removed.

Any insights or guidance on resolving this issue would be greatly appreciated!

heath-freenome commented 2 weeks ago

@AayushB This may be a duplicate of #4109. I know that there are several people possibly working on a solution to that bug.

AayushB commented 1 week ago

@heath-freenome Thank you for pointing out. While the issue is being addressed, is there way to bypass it somehow, as in is there a way to trigger onChange programmatically or on load so the omit logic takes effect.