-
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
Unwanted default value for object field (regression introduced in 5.22.0) #4361
Comments
@AlimovSV I'm not totally convinced it is a regression, but rather the result of fixing You can also not make the const be required. If you need it to be a required field then you can simply set the If that isn't acceptable, then let's discuss more. This is probably not the first time that people rely on a bug as if it was a feature. And then when the bug get fixed suddenly there is a "regression". |
@heath-freenome Thank you for response. I think this is still a bug because:
So the case where I want to force the user to make an initial choice is not possible. RJSF makes its choice.
Yes, and this behavior is correct, because I have "default: 1" in the schema. But in my example the schema does not have a default. I agree that if the schema is |
Hmmm, so maybe we add a new |
as a variant - may be. but I still think that the schema {
"type": "object",
"required": [
"prop"
],
"properties": {
"prop": {
"const": 1
}
}
} should have automatic const assignment, but this schema should not have it: {
"type": "object",
"required": [
"prop"
],
"properties": {
"prop": {
"type": "string",
"oneOf": [
{
"const": "1",
"title": "One"
},
{
"const": "2",
"title": "Two"
},
{
"const": "3",
"title": "Three"
}
]
}
}
} just because we are not 100% sure what value should be assigned to the data ("1", "2" or "3"). |
@AlimovSV what do you think of the proposal in this comment? Would the |
@nickgros Yes, thank you, I like it! |
…ression Fixes rjsf-team#4344, rjsf-team#4361 and rjsf-team#4377 - In `@rjsf/utils`: - Updated the `Experimental_DefaultFormStateBehavior` type to add new optional `constAsDefaults` prop with three choices - Updated `getDefaultFormState()` to respond to the new `constAsDefaults` feature to limit `const` as defaults based on the `never` or `skipOneOf` choices - Added tests for `getDefaultFormState()` to verify the new feature - In `@rjsf/core`: - Updated `SchemaField` to remove making the field readonly when const - In `playground`: - Updated `Header` to add support for `constAsDefaults` - Updated the `CHANGELOG.md` accordingly
…ression (#4381) Fixes #4344, #4361 and #4377 - In `@rjsf/utils`: - Updated the `Experimental_DefaultFormStateBehavior` type to add new optional `constAsDefaults` prop with three choices - Updated `getDefaultFormState()` to respond to the new `constAsDefaults` feature to limit `const` as defaults based on the `never` or `skipOneOf` choices - Added tests for `getDefaultFormState()` to verify the new feature - In `@rjsf/core`: - Updated `SchemaField` to remove making the field readonly when const - In `playground`: - Updated `Header` to add support for `constAsDefaults` - Updated the `CHANGELOG.md` accordingly
@nickgros Yet another issue I observed: when |
Prerequisites
What theme are you using?
core
Version
5.22.3
Current Behavior
If a schema contains an object field with subschema
oneOf: { const: 123 }
andemptyObjectFields <> 'skipDefaults'
, then the default value is applied as the first value from theoneOf
subschema.Expected Behavior
Object fields should not be populated if default value is not specified in the schema
Steps To Reproduce
Open playground: you will see a simple schema with one property WITHOUT default in the schema, but the RJSF set the default value as a first value from
oneOf
subschema. You can see this by trying to edit the form data (just try renamingprop
->prop2
andprop: 123
will be added automatically).Environment
Anything else?
No response
The text was updated successfully, but these errors were encountered: