-
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
Bug: Issue with array schema defaults not applying properly when formData is an empty array #4359
Bug: Issue with array schema defaults not applying properly when formData is an empty array #4359
Conversation
const arrayMinItemsStateBehavior = experimental_defaultFormStateBehavior?.arrayMinItems; | ||
const arrayMinItemsPopulate = arrayMinItemsStateBehavior?.populate; | ||
const arrayMergeExtraDefaults = arrayMinItemsStateBehavior?.mergeExtraDefaults; |
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.
consider doing this?:
const arrayMinItemsStateBehavior = experimental_defaultFormStateBehavior?.arrayMinItems; | |
const arrayMinItemsPopulate = arrayMinItemsStateBehavior?.populate; | |
const arrayMergeExtraDefaults = arrayMinItemsStateBehavior?.mergeExtraDefaults; | |
const { arrayMinItems: arrayMinItemsStateBehavior = {} } = experimental_defaultFormStateBehavior; | |
const { populate: arrayMinItemsPopulate, mergeExtraDefaults: arrayMergeExtraDefaults } = arrayMinItemsStateBehavior; |
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.
It's not possible to destructure experimental_defaultFormStateBehavior
since it can be undefined
but I improved it a little.
Also, would you be willing to change the example for these docs to switch |
@abdalla-rko Have you had the change to consider my feedback/request yet? |
Reasons for making this change
Fixes #4335
when you enable the
mergeExtraDefaults
and you haveformData
as an empty array, thedefault
on the root of the array schema doesn't get applied and only applies thedefault
from the items property. IfformData
is undefined or null, it will apply thedefault
from the root schema anditems.default
and the rootdefault
will take precedence overitem
property default.Checklist
npx nx run-many --target=build --exclude=@rjsf/docs && npm run test:update
to update snapshots, if needed.