Fix beforeunload dialog appearing on edit.php when no changes made

This commit is contained in:
Pontoporeia
2026-05-19 22:38:29 +02:00
parent 42222abe7c
commit 2e75a3b35c
3 changed files with 20 additions and 2 deletions

View File

@@ -535,22 +535,34 @@
console.log('[filepond] htmx detected, registering swap listeners');
window.htmx.on("htmx:beforeSwap", onHtmxBeforeSwap);
window.htmx.on("htmx:afterSwap", () => {
_xamxamFilepondReady = false;
window.XamxamInitFilePonds();
setTimeout(() => { _xamxamFilepondReady = true; }, 0);
});
}
// Flag set after FilePond instances are fully initialised.
// Before this flag is set, FilePond:addfile events are from initial load
// (e.g. existing files loaded in edit mode) and should not mark the form dirty.
let _xamxamFilepondReady = false;
tryRegisterHtmx();
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", () => {
window.XamxamInitFilePonds();
_xamxamFilepondReady = true;
});
} else {
window.XamxamInitFilePonds();
_xamxamFilepondReady = true;
}
// ── Mark form dirty on FilePond changes (beforeunload guard) ─────────
document.addEventListener("FilePond:addfile", () => {
window.__xamxamDirty = true;
if (_xamxamFilepondReady) window.__xamxamDirty = true;
});
document.addEventListener("FilePond:removefile", () => {
if (_xamxamFilepondReady) window.__xamxamDirty = true;
});
document.addEventListener("submit", (e) => {