diff --git a/core/src/main/resources/lib/form/confirm.js b/core/src/main/resources/lib/form/confirm.js index 1148eb016330..1bd3b248fcc5 100644 --- a/core/src/main/resources/lib/form/confirm.js +++ b/core/src/main/resources/lib/form/confirm.js @@ -117,5 +117,39 @@ } window.onbeforeunload = confirmExit; - window.addEventListener("load", initConfirm); + + function initWhenFormReady() { + const configForm = + document.getElementsByName("config")[0] || + document.getElementsByName("viewConfig")[0]; + + if (configForm) { + initConfirm(); + return true; + } + return false; + } + + function initWhenReady() { + if (initWhenFormReady()) { + return; + } + + const observer = new MutationObserver(function () { + if (initWhenFormReady()) { + observer.disconnect(); + } + }); + + observer.observe(document.body, { + childList: true, + subtree: true, + }); + } + + if (document.readyState === "complete") { + initWhenReady(); + } else { + window.addEventListener("load", initWhenReady); + } })();