-
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
Do not use "default" values from schema to initialize the form and underlying data structure #2980
Comments
@TheRealJon would it be ok to have an opt-out behavior instead since switching it to an opt-in behavior would be a major breaking change? |
Yes, I think the ideal solution would be opt-in (maybe in the next major release?), but even an opt-out option would be better than nothing in the meantime. |
There won't be time to get an |
I might be able to contribute an |
@TheRealJon Feel free to join the Friday meetings to discuss a way to potentially provide the opt-out solution in the v5 beta |
Fixes: rjsf-team#2691 better by providing an opt-out behavior for the automatic wrapping of fields by anyOf/oneOf components The original fix (rjsf-team#2980) to never wrap components is a breaking change from 4.x and could cause existing users problems. This new fix provides the opt-out instead thereby reversing the breaking change - In `@rjsf/utils`, updated just the `UiSchema` type to add the new `ui:fieldReplacesAnyOrOneOf` flag - In `@rjsf/core`, updated `SchemaField` to only skip wrapping a custom field in the `anyOf`/`oneOf` if the `ui:fieldReplacesAnyOrOneOf` is true along with there being a custom field - Updated/added tests to verify the fix - Updated the `uiSchema` documentation to include `ui:fieldReplacesAnyOrOneOf` - Updated the `CHANGELOG.md` accordingly
Fixes: rjsf-team#2691 better by providing an opt-out behavior for the automatic wrapping of fields by anyOf/oneOf components The original fix (rjsf-team#2980) to never wrap components is a breaking change from 4.x and could cause existing users problems. This new fix provides the opt-out instead thereby reversing the breaking change - In `@rjsf/utils`, updated just the `UiSchema` type to add the new `ui:fieldReplacesAnyOrOneOf` flag - In `@rjsf/core`, updated `SchemaField` to only skip wrapping a custom field in the `anyOf`/`oneOf` if the `ui:fieldReplacesAnyOrOneOf` is true along with there being a custom field - Updated/added tests to verify the fix - Updated the `uiSchema` documentation to include `ui:fieldReplacesAnyOrOneOf` - Updated the `CHANGELOG.md` accordingly
* Fix: 2691 with an opt-out for custom fields for anyOf/oneOf Fixes: #2691 better by providing an opt-out behavior for the automatic wrapping of fields by anyOf/oneOf components The original fix (#2980) to never wrap components is a breaking change from 4.x and could cause existing users problems. This new fix provides the opt-out instead thereby reversing the breaking change - In `@rjsf/utils`, updated just the `UiSchema` type to add the new `ui:fieldReplacesAnyOrOneOf` flag - In `@rjsf/core`, updated `SchemaField` to only skip wrapping a custom field in the `anyOf`/`oneOf` if the `ui:fieldReplacesAnyOrOneOf` is true along with there being a custom field - Updated/added tests to verify the fix - Updated the `uiSchema` documentation to include `ui:fieldReplacesAnyOrOneOf` - Updated the `CHANGELOG.md` accordingly * - Responded to reviewer feedback
#3663 should at least partially address this with an experimental fix in 5.X. We'd plan to remove the experimental prefix in v6.0 |
@nickgros Is it possible to keep this open until the current "pre-fill" behavior is opt-in rather than opt-out? Opting out provides a workaround, but the default behavior still doesn't semantically match what the JSON schema spec describes for "default" fields. |
@TheRealJon I think we have that covered in #3664 (which is slated to be addressed in v6), I'll add a note to that issue to clarify that the default behavior should change to more closely match the JSON Schema spec |
Great, I think that works! |
Prerequisites
What theme are you using?
core
Is your feature request related to a problem? Please describe.
JSON Schema defines the "default" property as such:
The key here is that the "default is typically used to express that if a value is missing, then the value is semantically the same as if the value was present with the default value"
If a missing value is semantically the same as a present default value, then it is probably best to exclude it for the sake of simplicity. The client shouldn't be concerned with the schema default, except for informational purposes ("...give hints to users about how to use a value."). It's a fallback value used on the server-side when no value is provided by the client. As such the client doesn't need to provide it at all unless it is different from the default.
Describe the solution you'd like
Do not fill in the form fields or underlying data structure with "default" values from the JSON schema, or at the very least, make this an opt-in behavior.
Describe alternatives you've considered
We do not want rjsf-generated forms to be pre-filled with default values from the schema. As a workaround, I'm currently working on a solution that will ignore values that are equal to schema defaults. If that doesn't work, we might have to modify the schema itself and remove defaults before rendering the form, which is definitely not ideal.
The text was updated successfully, but these errors were encountered: