-
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
formData definition in types should support undefined as a valid value #3305
Comments
@dagda1 Were you depending on that behavior? Many people had been complaining that this behavior was, in fact, a bug and so it was fixed in #3287. If we provided an Also, there is also a big issue (#2980) that indicates our automatically saving defaulting values in the formData is an actual bug itself, and that we should not do so ever. |
@heath-freenome me and @dagda1 discussed this a little bit, and we're happy that the behaviour is fine. However we noticed that the types for interface FieldProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> extends GenericObjectType, Pick<React.HTMLAttributes<HTMLElement>, Exclude<keyof React.HTMLAttributes<HTMLElement>, "onBlur" | "onFocus" | "onChange">> {
/** The data for this field */
formData: T; |
Thoughts @nickgros @epicfaace ? |
Good catch. I will be pushing a PR against this issue to fix |
Fixes rjsf-team#3305 by ensuring that `formData` can be optional everywhere There were some types which were requiring `formData` to be required even though it really can be optional everywhere - In `@rjsf/utils`, updated the `formData` prop in all types where it was required to make it optional - Also updated all function arguments where it was required to make `formData` optional - In `@rjsf/validator-ajv6` and `@rjsf/validator-ajv8`, updated places where `formData` was required as a function parameter to make it optional instead - In `@rjsf/core`, updated places where `formData` was required as a function parameter to make it optional instead - In `utility-functions.md`, updated the documentation of optional parameters without default values to ensure they included `| undefined` in the type of the parameter - In `5.x upgrade guide.md`, updated the note about improved typescript typing in `@rjsf/utils` to indicate that it may require updating typing in the user's implementations - Updated the `CHANGELOG.md` accordingly
Great! Thank you |
Fixes #3305 by ensuring that `formData` can be optional everywhere There were some types which were requiring `formData` to be required even though it really can be optional everywhere - In `@rjsf/utils`, updated the `formData` prop in all types where it was required to make it optional - Also updated all function arguments where it was required to make `formData` optional - In `@rjsf/validator-ajv6` and `@rjsf/validator-ajv8`, updated places where `formData` was required as a function parameter to make it optional instead - In `@rjsf/core`, updated places where `formData` was required as a function parameter to make it optional instead - In `utility-functions.md`, updated the documentation of optional parameters without default values to ensure they included `| undefined` in the type of the parameter - In `5.x upgrade guide.md`, updated the note about improved typescript typing in `@rjsf/utils` to indicate that it may require updating typing in the user's implementations - Updated the `CHANGELOG.md` accordingly
Fixes rjsf-team#3305 by ensuring that `formData` can be optional everywhere There were some types which were requiring `formData` to be required even though it really can be optional everywhere - In `@rjsf/utils`, updated the `formData` prop in all types where it was required to make it optional - Also updated all function arguments where it was required to make `formData` optional - In `@rjsf/validator-ajv6` and `@rjsf/validator-ajv8`, updated places where `formData` was required as a function parameter to make it optional instead - In `@rjsf/core`, updated places where `formData` was required as a function parameter to make it optional instead - In `utility-functions.md`, updated the documentation of optional parameters without default values to ensure they included `| undefined` in the type of the parameter - In `5.x upgrade guide.md`, updated the note about improved typescript typing in `@rjsf/utils` to indicate that it may require updating typing in the user's implementations - Updated the `CHANGELOG.md` accordingly
Fixes rjsf-team#3305 by ensuring that `formData` can be optional everywhere There were some types which were requiring `formData` to be required even though it really can be optional everywhere - In `@rjsf/utils`, updated the `formData` prop in all types where it was required to make it optional - Also updated all function arguments where it was required to make `formData` optional - In `@rjsf/validator-ajv6` and `@rjsf/validator-ajv8`, updated places where `formData` was required as a function parameter to make it optional instead - In `@rjsf/core`, updated places where `formData` was required as a function parameter to make it optional instead - In `utility-functions.md`, updated the documentation of optional parameters without default values to ensure they included `| undefined` in the type of the parameter - In `5.x upgrade guide.md`, updated the note about improved typescript typing in `@rjsf/utils` to indicate that it may require updating typing in the user's implementations - Updated the `CHANGELOG.md` accordingly
Prerequisites
What theme are you using?
core
Version
5.x
Current Behavior
In versions before
5.0.0-beta.*
, if the<Form />
was given a schema like this:The form component would call
getStateFromProps
which would, in turn, callcomputeDefaults
and return:This would allow
getDefaultFormState
to initialise the form correctly.The code in
computeDefaults
inv5.0.0-beta.*
has anisEmpty
check, meaning non-empty objects will not get initialised correctly, andformData
will be{}
.The knock-on effect of that is that this code in
ObjectField
will return undefined for the formData:Any
ui:field
will receiveundefined
for the initialformData
Expected Behavior
formData
should at least initialise to an empty object.Steps To Reproduce
I created a failing test here.
Environment
Anything else?
No response
The text was updated successfully, but these errors were encountered: