From cceef60cb84b86593b573f43d055501f484881b8 Mon Sep 17 00:00:00 2001 From: Johannes Eder Date: Sun, 28 Nov 2021 15:12:42 +0100 Subject: [PATCH] chore(navigate-away-prompt): add check if parent element contain a closed modal --- frontend/src/utils/form/navigate-away-prompt.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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; + } }