From 5252b76ef367e2f8deda1c5bc3402348919c1e11 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 15 May 2022 22:20:29 +0200 Subject: [PATCH] form bug fixes --- Message/Request/Request.js | 20 ++++++++++++++++++-- UI/Component/Form.js | 8 ++++++-- UI/Component/Table.js | 2 +- UI/GeneralUI.js | 8 +++++--- Uri/UriFactory.js | 2 +- 5 files changed, 31 insertions(+), 9 deletions(-) diff --git a/Message/Request/Request.js b/Message/Request/Request.js index 980dd17..b945c36 100755 --- a/Message/Request/Request.js +++ b/Message/Request/Request.js @@ -320,9 +320,12 @@ export class Request this.type = type; this.requestHeader['Content-Type'] = this.setContentTypeBasedOnType(this.type); + /* + @todo: why was i doing this? if (this.type === RequestType.FORM_DATA) { delete this.requestHeader['Content-Type']; } + */ }; /** @@ -374,7 +377,16 @@ export class Request const self = this; if (this.xhr.readyState !== 1) { - this.xhr.open(this.method, UriFactory.build(this.uri)); + if (this.type === RequestType.FORM_DATA) { + let url = this.uri; + for (let pair of this.data.entries()) { + url += '&' + pair[0] + '=' + pair[1]; + } + + this.xhr.open(this.method, UriFactory.build(url)); + } else { + this.xhr.open(this.method, UriFactory.build(this.uri)); + } for (const p in this.requestHeader) { if (Object.prototype.hasOwnProperty.call(this.requestHeader, p) && this.requestHeader[p] !== '') { @@ -409,7 +421,11 @@ export class Request } else if (this.type === RequestType.URL_ENCODE) { this.xhr.send(this.queryfy(this.data)); } else if (this.type === RequestType.FORM_DATA) { - this.xhr.send(this.data); + if (this.method === RequestMethod.GET) { + this.xhr.send(); + } else { + this.xhr.send(this.data); + } } }; }; diff --git a/UI/Component/Form.js b/UI/Component/Form.js index f9fe1a6..2ccab5f 100755 --- a/UI/Component/Form.js +++ b/UI/Component/Form.js @@ -796,7 +796,9 @@ export class Form // define remote response behavior self.forms[externalFormId].setSuccess(function (response) { - if (response.get('status') !== 'undefined' && response.get('status') !== NotificationLevel.HIDDEN) { + if (response.get('status') !== 'undefined' + && response.get('status') !== NotificationLevel.HIDDEN + ) { self.app.notifyManager.send( new NotificationMessage(response.get('status'), response.get('title'), response.get('message')), NotificationType.APP_NOTIFICATION ); @@ -810,7 +812,9 @@ export class Form Form.setDataFromRemoteUrls(remoteUrls); }); } - } else if ((elementIndex = Array.from(self.forms[id].getSubmit()).indexOf(event.target)) !== -1) { + } else if ((elementIndex = Array.from(self.forms[id].getSubmit()).indexOf(event.target)) !== -1 + || (elementIndex = Array.from(self.forms[id].getSubmit()).indexOf(event.target.parentNode)) !== -1 + ) { jsOMS.preventAll(event); self.submit(self.forms[id], self.forms[id].getSubmit()[elementIndex]); } diff --git a/UI/Component/Table.js b/UI/Component/Table.js index a49ca6c..05232eb 100755 --- a/UI/Component/Table.js +++ b/UI/Component/Table.js @@ -293,7 +293,7 @@ export class Table { sorting.addEventListener('click', function (event) { - if (this.firstElementChild.tagName.toLowerCase() === 'a') { + if (this.firstElementChild === null || this.firstElementChild.tagName.toLowerCase() === 'a') { // page is getting reloaded return; } diff --git a/UI/GeneralUI.js b/UI/GeneralUI.js index 6540839..2cd9d94 100755 --- a/UI/GeneralUI.js +++ b/UI/GeneralUI.js @@ -81,9 +81,8 @@ export class GeneralUI if (input !== null) { input.click(); + return; } - - return; } jsOMS.preventAll(event); @@ -92,7 +91,10 @@ export class GeneralUI let uri = this.getAttribute('data-href'); uri = uri === null ? this.getAttribute('href') : uri; - if (this.getAttribute('target') === '_blank' || this.getAttribute(['data-target']) === '_blank' || event.button === 1) { + if (this.getAttribute('target') === '_blank' + || this.getAttribute(['data-target']) === '_blank' + || event.button === 1 + ) { window.open(UriFactory.build(uri), '_blank'); } else { window.location = UriFactory.build(uri); diff --git a/Uri/UriFactory.js b/Uri/UriFactory.js index 8558ed0..9eef658 100755 --- a/Uri/UriFactory.js +++ b/Uri/UriFactory.js @@ -203,7 +203,7 @@ export class UriFactory } } - let parsed = uri.replace(new RegExp('\{[\/#\?%@\.\$\!][a-zA-Z0-9\-\#\.]*\}', 'g'), function (match) { + let parsed = uri.replace(new RegExp('\{[\/#\?%@\.\$\!][a-zA-Z0-9_\\-#\.]*\}', 'g'), function (match) { match = match.substr(1, match.length - 2); if (toMatch !== null && Object.prototype.hasOwnProperty.call(toMatch, match)) {