mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
Fix beforeunload dialog appearing on edit.php when no changes made
This commit is contained in:
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user