diff --git a/layouts/v7/resources/application.js b/layouts/v7/resources/application.js index dc2188cdaf9106cb58910ad78890a74aec937094..e3117227d7e28964474e53dda879f909218194e1 100644 --- a/layouts/v7/resources/application.js +++ b/layouts/v7/resources/application.js @@ -111,6 +111,23 @@ window.app = (function () { params.data = app.convertUrlToDataParams(params.url); delete params.url; } + + /** + * Safari 11.1 - ajax/XHR form submission will fail if input[type=file] is empty in formData. + */ + var isIOSDevice = navigator.userAgent.match(/iPhone|iPod|iPad/i) != null; + if ((!!window.safari === true || isIOSDevice) + && params.data instanceof FormData && typeof params.data.getAll == 'function') { + var fileNameAttribute = (params.data.getAll("filename[]").length > 0) ? 'filename[]' : 'file[]'; + var fileNames = params.data.getAll(fileNameAttribute); + params.data.delete(fileNameAttribute); + jQuery.each(fileNames, function (key, fileNameObject) { + if (fileNameObject.name) { + params.data.append(fileNameAttribute, fileNameObject); + } + }); + } + this._request(params).then(function (err, data) { return aDeferred.resolve(err, data); });