Skip to content

Commit 4f84169

Browse files
Fix for Object.entries(formData) in getFormData
When you use Object.entries(formData), it attempts to convert the FormData object into an array of key-value pairs, as it would with a regular JavaScript object. However, since FormData doesn't store its data in enumerable properties, Object.entries returns an empty array. This will not work: Object.entries(options.formData) .filter(([_, value]) => isDefined(value)) .forEach(([key, value]) => { if (Array.isArray(value)) { value.forEach(v => process(key, v)); } else { process(key, value); } }); On the other hand, formData.entries() is a method specifically provided by the FormData interface. It returns an iterator allowing for the traversal of all key/value pairs contained in the FormData object. This method is designed to understand and interact with the internal structure of FormData, so it successfully retrieves the data. This will work: for (let [key, value] of options.formData.entries()) { if (isDefined(value)) { if (Array.isArray(value)) { value.forEach((v) => process(key, v)); } else { process(key, value); } } }
1 parent 311ffd8 commit 4f84169

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/templates/core/functions/getFormData.hbs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ export const getFormData = (options: ApiRequestOptions): FormData | undefined =>
1010
}
1111
};
1212

13-
Object.entries(options.formData)
14-
.filter(([_, value]) => isDefined(value))
15-
.forEach(([key, value]) => {
16-
if (Array.isArray(value)) {
17-
value.forEach(v => process(key, v));
18-
} else {
19-
process(key, value);
20-
}
21-
});
13+
for (let [key, value] of options.formData.entries()) {
14+
if (isDefined(value)) {
15+
if (Array.isArray(value)) {
16+
value.forEach((v) => process(key, v));
17+
} else {
18+
process(key, value);
19+
}
20+
}
21+
}
2222

2323
return formData;
2424
}

0 commit comments

Comments
 (0)