Skip to content

Commit 254da2f

Browse files
Add check for empty object for assessing optional fields that are objects
Signed-off-by: Natalia Luzuriaga <natalia.luzuriaga@cms.hhs.gov>
1 parent 706e830 commit 254da2f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

js/formDataToJson.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ function getSelectedOptions(options) {
3737
return selectedOptions;
3838
}
3939

40+
function isEmptyObject(obj) {
41+
return Object.values(obj).every(value =>
42+
value === "" ||
43+
value === null ||
44+
value === undefined
45+
);
46+
}
47+
4048
// Populates fields with form data
4149
function populateObject(data, fields) {
4250
let reorderedObject = {}
@@ -45,7 +53,7 @@ function populateObject(data, fields) {
4553
let value = data[field];
4654

4755
// Does not assign optional properties with blank values
48-
if (value == null || value === "") {
56+
if (value == null || value === "" || (Array.isArray(value) && typeof value[0] === 'object' && isEmptyObject(value[0]))) {
4957
continue;
5058
}
5159

0 commit comments

Comments
 (0)