Skip to content

Commit

Permalink
Fix: form data converter (#6908)
Browse files Browse the repository at this point in the history
* fix: convert non-primitive values to associative arrays

* refactor: add check for null values

* fix: re-add mistakenly removed keyword

Co-authored-by: Jon Waldstein <[email protected]>

---------

Co-authored-by: Jon Waldstein <[email protected]>
  • Loading branch information
pauloiankoski and jonwaldstein authored Aug 29, 2023
1 parent b5883f9 commit f9a39c1
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
*/
export default function convertValuesToFormData(values: object): FormData {
const formData = new FormData();
for (const valueKey in values) {
const value = values[valueKey];

for (const key in values) {
formData.append(key, values[key]);
if (value !== null && typeof value === 'object') {
for (const objKey in value) {
formData.append(`${valueKey}[${objKey}]`, value[objKey]);
}
} else {
formData.append(valueKey, value);
}
}

return formData;
Expand Down

0 comments on commit f9a39c1

Please sign in to comment.