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

Default values not changing when dependencies updated #4325

Open
4 tasks done
chopfitzroy opened this issue Oct 3, 2024 · 3 comments
Open
4 tasks done

Default values not changing when dependencies updated #4325

chopfitzroy opened this issue Oct 3, 2024 · 3 comments
Labels
any-one-all-of Related to fixing anyOf, oneOf or allOf bug defaults dependencies help wanted if-then-else Issues related to handling JSON Schema if/then/else

Comments

@chopfitzroy
Copy link

chopfitzroy commented Oct 3, 2024

Prerequisites

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.

These issues may also be tangentially related but it is hard to tell:

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

@chopfitzroy chopfitzroy added bug needs triage Initial label given, to be assigned correct labels and assigned labels Oct 3, 2024
@heath-freenome heath-freenome removed the needs triage Initial label given, to be assigned correct labels and assigned label Oct 4, 2024
@nickgros
Copy link
Contributor

nickgros commented Oct 7, 2024

@chopfitzroy Your second CodeSandbox isn't working for me. Can you check that it's shared publicly?

@nickgros
Copy link
Contributor

nickgros commented Oct 7, 2024

I expected this to work if we set the experimental_defaultFormStateBehavior to { allOf: 'populateDefaults' } but that didn't work. Definitely a bug here. I think we have a few similar reports related to conditional logic, allOf, and computing default values.

@nickgros nickgros added help wanted dependencies defaults any-one-all-of Related to fixing anyOf, oneOf or allOf if-then-else Issues related to handling JSON Schema if/then/else labels Oct 7, 2024
@chopfitzroy
Copy link
Author

@nickgros sorry about that! Link is public now.

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 defaults dependencies help wanted if-then-else Issues related to handling JSON Schema if/then/else
Projects
None yet
Development

No branches or pull requests

3 participants