diff --git a/packages/app-rfi/src/components/controls/RfiSelect.js b/packages/app-rfi/src/components/controls/RfiSelect.js index 9d031f58d7..5074d0b364 100644 --- a/packages/app-rfi/src/components/controls/RfiSelect.js +++ b/packages/app-rfi/src/components/controls/RfiSelect.js @@ -44,7 +44,7 @@ const RfiSelect = ({ ({})) => { // MARSHALL FIELDS FOR THE PAYLOAD - let payload = value; + let payload = deepCloner(value); payload = submissionFormFieldPrep(payload); payload = submissionSetHiddenFields(payload, test); payload = removeUnansweredFields(payload); diff --git a/shared/utils/deep-cloner.js b/shared/utils/deep-cloner.js new file mode 100644 index 0000000000..0ec63eb86f --- /dev/null +++ b/shared/utils/deep-cloner.js @@ -0,0 +1,31 @@ +function deepCloner(obj) { + // Check if the object is null or not an object, return it if so + if (obj === null || typeof obj !== 'object') { + return obj; + } + + // Handle Date + if (obj instanceof Date) { + return new Date(obj.getTime()); + } + + // Handle Array + if (Array.isArray(obj)) { + const arrCopy = []; + for (let i = 0; i < obj.length; i++) { + arrCopy[i] = deepClone(obj[i]); + } + return arrCopy; + } + + // Handle Object + const objCopy = {}; + for (const key in obj) { + if (obj.hasOwnProperty(key)) { + objCopy[key] = deepCloner(obj[key]); + } + } + return objCopy; +}; + +export { deepCloner }; diff --git a/shared/utils/index.js b/shared/utils/index.js index 3850f85914..9be2d9f750 100644 --- a/shared/utils/index.js +++ b/shared/utils/index.js @@ -18,3 +18,4 @@ export * from "./id-generator"; export * from "./numbers"; export * from "./script-utils"; export * from "./timers"; +export * from "./deep-cloner";