From 63aaefbcfc29b4222b033957c3138a90ca6faf4a Mon Sep 17 00:00:00 2001 From: joepuzzo Date: Wed, 9 Mar 2022 13:57:56 -0800 Subject: [PATCH] issue with changing options on schema fields --- src/utils.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/utils.js b/src/utils.js index 2c99bc6c..89e11208 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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; };