-
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
Fix 3759 - uneditable & permanent defaults with additional properties #4490
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Heath C <[email protected]>
@@ -687,6 +699,7 @@ export default function getDefaultFormState< | |||
theSchema: S, | |||
formData?: T, | |||
rootSchema?: S, | |||
initialDefaultsGenerated?: boolean, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Piotr-Debicki Unfortunately, unless you add it to the end of the function call, you are introducing a breaking change. This will need to be the LAST, optional, parameter to the function.
@@ -111,13 +112,15 @@ class SchemaUtils<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo | |||
getDefaultFormState( | |||
schema: S, | |||
formData?: T, | |||
initialDefaultsGenerated?: boolean, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Piotr-Debicki Unfortunately, unless you add it to the end of the function call, you are introducing a breaking change. This will need to be the LAST, optional, parameter to the function.
@@ -1082,6 +1083,7 @@ export interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchem | |||
getDefaultFormState( | |||
schema: S, | |||
formData?: T, | |||
initialDefaultsGenerated?: boolean, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Piotr-Debicki Unfortunately, unless you add it to the end of the function call, you are introducing a breaking change. This will need to be the LAST, optional, parameter to the function.
Reasons for making this change
Fixes #3759
Additional properties with defaults set currently creates a permanent key-value pair that is essentially uneditable.
Trying to edit the key creates an entirely new key value entry on blur while still keeping the default key-value pair. The default key-value pair is also not deletable. Solution here generates defaults for additional properties once on form initialization, and then skips regeneration on any form update
This solution works for root & nested additionalProperties (see tests)
Allows for 'reset' form to regenerate additionalProperties defaults
Also fixes the issue I mentioned in the Closed PR with custom formData not being applied when generating additionalProperties defaults
Checklist
npx nx run-many --target=build --exclude=@rjsf/docs && npm run test:update
to update snapshots, if needed.