Skip to content
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

[RFR] Support array of objects in sanitizeEmptyValues #4853

Merged

Conversation

armellarcier
Copy link
Contributor

Fixes #4726

This will not support an array of objects with different structure AND key reordering.

@armellarcier armellarcier force-pushed the fix-sanitizeEmptyValues-4726 branch 2 times, most recently from 8f2437c to 73f8ac4 Compare May 25, 2020 21:56
Copy link
Collaborator

@djhi djhi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@djhi djhi added this to the 3.5.4 milestone May 26, 2020
@fzaninotto fzaninotto merged commit 5e247b9 into marmelab:master May 26, 2020
@fzaninotto
Copy link
Member

Thanks!

@armellarcier
Copy link
Contributor Author

Glad I could help. As I stated in the PR description, this fixes a problem and should be a good solution for the vast majority of use cases but an array being what it is, reordering an array of objects with different structures will lead to props with null values in objects that didn’t have the prop in the first place. This is not perfect. Maybe the parse={identity} option should be considered (in « userland » as you may say).

@@ -16,8 +16,16 @@ const sanitizeEmptyValues = (initialValues: object, values: object) => {
if (!initialValues) return values;
const initialValuesWithEmptyFields = Object.keys(initialValues).reduce(
(acc, key) => {
if (values[key] instanceof Date || Array.isArray(values[key])) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if values is null or undefined? is it possible? shouldn't there be an if for that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Empty values of object in an array are not sanitized by sanitizeEmptyValues
4 participants