-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Use default values when switching anyOf option #4375
base: main
Are you sure you want to change the base?
Conversation
@quentin-sommer A couple of thoughts: Does your change fix the original issue in #4367 ? When I tried it locally it did not seem to fix it, but I want to confirm with you. Instead of changing if (newFormData && newOption) { to if (newOption) { Your test seems to pass with this change, but I want to make sure I'm not missing an edge case I am unaware of. |
396fd5f
to
756af61
Compare
I applied your suggestion and it fixes the original issue in #4367 as well as the schema in this PR description, thanks! I also added a changelog entry. Let me know if this looks good to go |
@@ -165,6 +165,43 @@ describe('anyOf', () => { | |||
); | |||
}); | |||
|
|||
it('should assign a default value and set defaults on option change for scalar types schemas', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a similar test for the oneOf.test.jsx
file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing, PR updated 👍
Reasons for making this change
The UI wasn't properly handling the option change resulting in undefined data (See my video in #4367).
In summary this change makes this schema work as expected:
But when removing thedefault
value for the array field the UI doesn't render a + button. I have no idea how/where to fix this. In the playground an array without data is rendered with a +. I expect there is a function somewhere that can provide a default value for thisWorks after @nickgros's suggestion
fixes #4367
Checklist
npx nx run-many --target=build --exclude=@rjsf/docs && npm run test:update
to update snapshots, if needed.