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.33k stars 2.19k forks source link

Omit Extra Data not behaving as expected on submit for allOf (if then) schemas along with additionalProperties set to false blocking form submission #4165

Closed sahanaamurthy closed 5 months ago

sahanaamurthy commented 6 months ago

Prerequisites

What theme are you using?

mui

Version

5.18.1

Current Behavior

Form has two params - omitExtraData and liveOmit If both are set to true, any schema changes occurring through allOf (if-then) will remove the previous data (schema and form data) onChange If omitExtraData alone is set to true, it is not performing the same action onSubmit. Due to this, the live validation is throwing an error indicating the 'then' schema is not matching because the previously selected 'then' schema is not being removed, blocking the users from submitting the form.

Expected Behavior

If omitExtraData alone is set to true, it is expected to function properly during onSubmit just like the combination of omitExtraData and liveOmit performs during onChange. At least that's what I understand from the documentation.

Steps To Reproduce

In https://rjsf-team.github.io/react-jsonschema-form/, I tried the following allOf (if-then) schema with additionalProperties:false It works when both liveOmit and omitExtraData is set to true but with just omitExtraData, it blocks the user from submitting the form

https://github.com/rjsf-team/react-jsonschema-form/assets/16612102/b3697054-1325-44ef-8a39-cef0bd6d0100

{ "type": "object", "properties": { "animal": { "type": "string", "enum": [ "Cat", "Fish" ] } }, "required": [ "animal" ], "allOf": [ { "if": { "properties": { "animal": { "const": "Cat" } } }, "then": { "properties": { "food": { "type": "object", "properties": { "catFoodItems": { "type": "array", "items": { "type": "string" } } }, "additionalProperties": false, "required": [ "catFoodItems" ] } } } }, { "if": { "properties": { "animal": { "const": "Fish" } } }, "then": { "properties": { "food": { "type": "object", "properties": { "fishFoodOptionA": { "type": "string" }, "fishFoodOptionB": { "type": "string" } }, "additionalProperties": false, "required": [ "fishFoodOptionA", "fishFoodOptionB" ] } } } } ] }

Environment

- OS: macOS 14.2.1
- Node: 20.10.0
- npm: 10.2.3

Anything else?

https://github.com/rjsf-team/react-jsonschema-form/assets/16612102/a3b55874-c887-4828-9e7c-7f5bee8f998d

nickgros commented 6 months ago

Thanks for the report. I think this is a duplicate of #4109

stale[bot] commented 5 months ago

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