-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
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 sample JSFiddle, Codesandbox.io or preferably a shared playground link demonstrating the issue.
What theme are you using?
core
Version
5.x
Current Behavior
Trying to use default
values with dependencies
but the formData
does not update.
Visually the form does update which is quite confusing for the user. Fortunately if the user tries to submit the validation does catch the error.
Interestingly if I use if
/ then
the issue presents the same but I do see warnings in the console, example here: https://codesandbox.io/p/sandbox/nagaozen-react-jsonschema-form-playground-forked-8g34z7 (this is different from the Codesandbox link below, please check both)
A number of issues suggest that this may be to do with uncontrolled vs. controlled forms but I have tried with both.
- default value does not work #975
- Dependency defaults do not render for uncontrolled Form components #1316
- Selector not working inside dependency for uncontrolled components #1394
- Playground support for uncontrolled components #1399
These issues may also be tangentially related but it is hard to tell:
- OneOf not able to retain the default values when switching between the options #4322
- oneOf not selecting correct default value for complex objects with the same property keys #4208
- Default values not set inside allOf #3892
Expected Behavior
When changing from Cat to Fish I expect the formData
to update food
from "meat"
to "worms"
.
Steps To Reproduce
Example here: https://codesandbox.io/p/sandbox/nagaozen-react-jsonschema-form-playground-forked-t8f767
- Select Cat
- Check console should see
{food: 'meat', animal: 'Cat'}
- Select Fish
- Check console should see
{food: 'meat', water: 'sea', animal: 'Fish'}
- Try to submit the form - validation should prevent this
NOTE: The inverse is also true if you start with Fish and then select Cat food
will be "worms"
Environment
- OS: WSL 2 - OpenSuse Tumbleweed
- Node: v22.6.0
- npm: 10.8.2
Anything else?
No response