From 9ad557e77cd10bdd5e0acd9730681c2b0ff0f646 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Thu, 20 Jun 2019 17:09:46 +0200 Subject: [PATCH] Fix form builder dialog cancel button after form validation error See #2509 --- .../WoltLabSuite/Core/Form/Builder/Dialog.js | 49 +++++++++---------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Dialog.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Dialog.js index 6bf2009b8c..96528008a9 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Dialog.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Dialog.js @@ -35,8 +35,7 @@ define(['Ajax', 'Core', './Manager', 'Ui/Dialog'], function(Ajax, Core, FormBuil usesDboAction: this._className.match(/\w+\\data\\/) }, options); this._options.dialog = Core.extend(this._options.dialog || {}, { - onClose: this._dialogOnClose.bind(this), - onSetup: this._dialogOnSetup.bind(this) + onClose: this._dialogOnClose.bind(this) }); this._formId = ''; @@ -86,12 +85,7 @@ define(['Ajax', 'Core', './Manager', 'Ui/Dialog'], function(Ajax, Core, FormBuil throw new Error("Missing form id in return data."); } - this.destroy(true); - - this._formId = data.returnValues.formId; - this._dialogContent = data.returnValues.dialog; - - UiDialog.open(this, this._dialogContent); + this._openDialogContent(data.returnValues.formId, data.returnValues.dialog); break; @@ -102,11 +96,7 @@ define(['Ajax', 'Core', './Manager', 'Ui/Dialog'], function(Ajax, Core, FormBuil throw new Error("Mismatch between form ids: expected '" + this._formId + "' but got '" + data.returnValues.formId + "'."); } - this.destroy(true); - - this._dialogContent = data.returnValues.dialog; - - UiDialog.open(this, this._dialogContent); + this._openDialogContent(data.returnValues.formId, data.returnValues.dialog); } else { this.destroy(); @@ -130,18 +120,6 @@ define(['Ajax', 'Core', './Manager', 'Ui/Dialog'], function(Ajax, Core, FormBuil UiDialog.close(this); }, - /** - * Is called when the dialog is set up. - * - * @param {HTMLElement} content dialog's content element - */ - _dialogOnSetup: function(content) { - var cancelButton = elBySel('button[data-type=cancel]', content); - if (cancelButton !== null) { - cancelButton.addEventListener('click', this._closeDialog.bind(this)); - } - }, - /** * Is called by the dialog API when the dialog is closed. */ @@ -171,6 +149,27 @@ define(['Ajax', 'Core', './Manager', 'Ui/Dialog'], function(Ajax, Core, FormBuil this.getData().then(this._submitForm.bind(this)); }, + /** + * Opens the form dialog with the given form content. + * + * @param {string} formId + * @param {string} dialogContent + */ + _openDialogContent: function(formId, dialogContent) { + this.destroy(true); + + this._formId = formId; + this._dialogContent = dialogContent; + + var dialogData = UiDialog.open(this, this._dialogContent); + + var cancelButton = elBySel('button[data-type=cancel]', dialogData.content); + if (cancelButton !== null && !elDataBool(cancelButton, 'has-event-listener')) { + cancelButton.addEventListener('click', this._closeDialog.bind(this)); + elData(cancelButton, 'has-event-listener', 1); + } + }, + /** * Submits the form with the given form data. * -- 2.20.1