Skip to content

Commit

Permalink
issue with changing options on schema fields
Browse files Browse the repository at this point in the history
  • Loading branch information
joepuzzo committed Mar 9, 2022
1 parent 623a1fa commit 63aaefb
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,14 @@ export const generateValue = ({ fieldType, maskedValue, multiple, value }) => {
}
};

// https://stackoverflow.com/questions/52367849/remove-empty-null-values-from-nested-object-es6-clean-nested-objects
export const sanitize = obj => {
if (obj) {
const cleaned = JSON.parse(
JSON.stringify(obj, (key, value) => {
return value === undefined ? undefined : value;
})
);
return cleaned;
}
if (!obj) return obj;
Object.keys(obj).forEach(
key =>
(obj[key] && typeof obj[key] === 'object' && sanitize(obj[key])) ||
(obj[key] === undefined && delete obj[key])
);
return obj;
};

Expand Down

0 comments on commit 63aaefb

Please sign in to comment.