Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prev. selected oneOf schema properties removed only IF populated when schema changes #3442

Open
4 tasks done
tmlstevens opened this issue Feb 10, 2023 · 1 comment · May be fixed by #3443
Open
4 tasks done

Prev. selected oneOf schema properties removed only IF populated when schema changes #3442

tmlstevens opened this issue Feb 10, 2023 · 1 comment · May be fixed by #3443
Labels
any-one-all-of Related to fixing anyOf, oneOf or allOf bug

Comments

@tmlstevens
Copy link

tmlstevens commented Feb 10, 2023

Prerequisites

  • I have searched the existing issues
  • I understand that providing a SSCCE example is tremendously useful to the maintainers.
  • I have read the documentation
  • Ideally, I'm providing a shared playground link demonstrating the issue.

What theme are you using?

bootstrap-4

Version

5.x

Current Behavior

Given a oneOf schema for which the possible types are object - when user selects a different subschema, properties unique to the old/previously selected subschema are not removed unless they were populated when user selected the new/current subschema. Therefore, if a user toggles/selects through each oneOf subschema, without populating unique properties props.formData will accumulate an invalid payload. However, if user populates unique properties before selecting different subschema, those properties are removed from formData when the new subschema is selected and form loaded.

This behavior is observable when props.formData is returned to Form component's onChange handler function. Properties unique to previously selected oneOf subschema(s) that were not populated are found in the formData, with values set to undefined. Upon form submission, errors will be thrown as the submitted object contains a conglomeration of properties not conforming to any of the oneOf subschemas.

This is very similar to the issue reported in 2183, however, with the v.5x refactor and implementation of sanitizeDataForNewSchema it seems somewhat different. Further, my proposed solution only resolves the issue in v5.x.

Expected Behavior

I expect properties unique to old/previously selected subschema to be removed, whether populated or not, from props.fomData when new/current subschema is selected, since they are irrelevant/out-of-scope when new subschema is selected.

Steps To Reproduce

  1. go to the playground setup
  2. observe that Option 1 is selected by default
  3. do not enter data, select Option 2
  4. do not enter data, select Option 3
  5. populate the fields and submit the form
  6. observe the errors

Environment

- OS: RHEL 8.6
- Node: 14.20.1
- npm: 6.14.17

Anything else?

It seems to me that properties unique to old/previously selected subschema should be discarded when the new/current subschema is selected; they should not be returned in the formData. But for some reason those properties are persisted and their values set to undefined, but maybe there's a reason?

@tmlstevens tmlstevens added bug needs triage Initial label given, to be assigned correct labels and assigned labels Feb 10, 2023
@tmlstevens tmlstevens linked a pull request Feb 10, 2023 that will close this issue
@tmlstevens tmlstevens changed the title Prev. selected oneOf schema keys removed only IF populated Prev. selected oneOf schema keys removed only IF populated when subschema changes Feb 13, 2023
@tmlstevens tmlstevens changed the title Prev. selected oneOf schema keys removed only IF populated when subschema changes Prev. selected oneOf schema properties removed only IF populated when subschema changes Feb 13, 2023
@tmlstevens tmlstevens changed the title Prev. selected oneOf schema properties removed only IF populated when subschema changes Prev. selected oneOf schema properties removed only IF populated when schema changes Feb 13, 2023
@heath-freenome heath-freenome added any-one-all-of Related to fixing anyOf, oneOf or allOf and removed needs triage Initial label given, to be assigned correct labels and assigned labels Feb 24, 2023
@heath-freenome
Copy link
Member

@tmlstevens awaiting changes to your PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
any-one-all-of Related to fixing anyOf, oneOf or allOf bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants