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

Fields without default values not resetting after changing oneOf options #4419

Open
4 tasks done
Maxx016 opened this issue Dec 18, 2024 · 1 comment
Open
4 tasks done
Labels
any-one-all-of Related to fixing anyOf, oneOf or allOf awaiting response bug

Comments

@Maxx016
Copy link

Maxx016 commented Dec 18, 2024

Prerequisites

What theme are you using?

mui

Version

5.23.2

Current Behavior

I have this oneOf (playground link) with several fields, first two with default values and the last two without default values. If I select Option1 for example and change either "someDate" or "someValue", not both, and then change Option1 to Option2, the changed field resets as expected. If I insert formData for both "someDate" and "someValue", after changing the option in the dropdown to Option2, the fields don't reset.

Expected Behavior

To reset inserted formData for both fields when changing oneOf dropdown options, as those fields in my case do not have default values.

Steps To Reproduce

Playground link

Environment

- OS: macOS Sequoia 15.2
- Node: 20.18.1
- npm: 10.8.2

Anything else?

No response

@Maxx016 Maxx016 added bug needs triage Initial label given, to be assigned correct labels and assigned labels Dec 18, 2024
@nickgros
Copy link
Contributor

@Maxx016 Since the field names are the same, the supported behavior is actually to keep the current data when changing between options. I am not sure if we have a native way to clear the options to match your expected behavior. That said, this still looks like a bug because the behavior is not consistent.

Historically, RJSF has had unusual behavior when using liveOmit with anyOf or oneOf. This seems similar to #4314, but not quite.

There are a couple of flags in the experimental_defaultFormStateBehavior prop that you can manipulate to try to get some acceptable behavior, particularly the emptyObjectFields and mergeDefaultsIntoFormData properties.

If you can't manage to get satisfactory behavior, we might need some help debugging to figure out exactly where something is going wrong. If you are interested and have the time for that, you might want to start in @rjsf/core's Form.tsx and look at where liveOmit ends up leading to a call to this.omitExtraData

@nickgros nickgros added awaiting response 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 Jan 13, 2025
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 awaiting response bug
Projects
None yet
Development

No branches or pull requests

2 participants