diff --git a/frontend/src/utils/form/navigate-away-prompt.js b/frontend/src/utils/form/navigate-away-prompt.js index da900ba72..69c430853 100644 --- a/frontend/src/utils/form/navigate-away-prompt.js +++ b/frontend/src/utils/form/navigate-away-prompt.js @@ -107,7 +107,7 @@ export class NavigateAwayPrompt { // allow the event to happen if the form was not touched by the // user (i.e. if the current FormData is equal to the initial FormData) // or the unload event was initiated by a form submit - if (!formDataHasChanged || this.unloadDueToSubmit) + if (!formDataHasChanged || this.unloadDueToSubmit || this._parentModalIsClosed()) return; // cancel the unload event. This is the standard to force the prompt to appear. @@ -117,4 +117,13 @@ export class NavigateAwayPrompt { // for all non standard compliant browsers we return a truthy value to activate the prompt. return true; } + + _parentModalIsClosed() { + const parentModal = this._element.closest('.modal'); + if (!parentModal) + return false; + + const modalClosed = !parentModal.classList.contains('modal--open'); + return modalClosed; + } } diff --git a/frontend/src/utils/modal/modal.js b/frontend/src/utils/modal/modal.js index 8f013572f..6b8e28a17 100644 --- a/frontend/src/utils/modal/modal.js +++ b/frontend/src/utils/modal/modal.js @@ -72,16 +72,7 @@ export class Modal { } destroy() { - this._eventManager.cleanUp(); - if (this._closerElement !== undefined) - this._closerElement.remove(); - if(this._triggerElement !== undefined) - this._triggerElement.classList.remove(MODAL_TRIGGER_CLASS); - if(this._modalsWrapper !== undefined) - this._modalsWrapper.remove(); - if(this._modalOverlay !== undefined) - this._modalOverlay.remove(); - this._element.classList.remove(MODAL_INITIALIZED_CLASS, MODAL_CLASS); + throw new Error('Destroying modals is not possible.'); } _ensureModalWrapper() { @@ -164,7 +155,6 @@ export class Modal { this._modalsWrapper.classList.remove(MODALS_WRAPPER_OPEN_CLASS); document.removeEventListener('keyup', this._onKeyUp); - this._app.utilRegistry.destroyAll(this._element); }; _fillModal(url) {