From 6f49e9b80f88e0154895bc6975fb029d630bd8a6 Mon Sep 17 00:00:00 2001 From: djmaze Date: Sat, 15 Aug 2020 22:12:57 +0200 Subject: [PATCH] Bugfix: new AbstractAjaxRemote failed with recursive values like the Attachments --- dev/Remote/AbstractAjax.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/dev/Remote/AbstractAjax.js b/dev/Remote/AbstractAjax.js index 48263dafb..5c6ab17a6 100644 --- a/dev/Remote/AbstractAjax.js +++ b/dev/Remote/AbstractAjax.js @@ -152,10 +152,17 @@ class AbstractAjaxRemote { }; params.XToken = Settings.appSettingsGet('token'); // init.body = JSON.stringify(params); - const formData = new FormData(); - Object.keys(params).forEach(key => { - formData.append(key, params[key]) - }); + const formData = new FormData(), + buildFormData = (formData, data, parentKey) => { + if (data && typeof data === 'object' && !(data instanceof Date || data instanceof File)) { + Object.entries(data).forEach(([key,value]) => { + buildFormData(formData, value, parentKey ? `${parentKey}[${key}]` : key); + }); + } else { + formData.append(parentKey, data == null ? '' : data); + } + }; + buildFormData(formData, params); init.body = (new URLSearchParams(formData)).toString(); }