FIX: back-links in bearbeiten-Formularen

This commit is contained in:
Simon Martens
2026-01-29 14:16:57 +01:00
parent ff85e83dc7
commit 459c15b409
22 changed files with 591 additions and 525 deletions

View File

@@ -179,6 +179,31 @@ function ShowBoostedErrors() {
});
}
function setupCancelLinks(root = document) {
const links = root.querySelectorAll("[data-role='cancel-link']");
links.forEach((link) => {
if (link.dataset.cancelBound === "true") {
return;
}
link.dataset.cancelBound = "true";
const cancelUrl = (link.getAttribute("data-cancel-url") || "").trim();
if (cancelUrl) {
link.setAttribute("href", cancelUrl);
return;
}
link.addEventListener("click", (event) => {
const resolved = (link.getAttribute("data-cancel-url") || "").trim();
if (resolved) {
return;
}
event.preventDefault();
if (window.history.length > 1) {
window.history.back();
}
});
});
}
// INFO: Hooks up to all the reset button children of the target element.
// If an element has a changed state, it will trigger the action with `true`.
// If no elements are changed, it will trigger the action with `false`.
@@ -224,6 +249,15 @@ function supportsFieldSizing() {
return browserSupportsFieldSizing;
}
document.addEventListener("DOMContentLoaded", () => {
setupCancelLinks(document);
});
document.addEventListener("htmx:afterSwap", (event) => {
const root = event.detail?.target || document;
setupCancelLinks(root);
});
// Simple textarea auto-resize function
function TextareaAutoResize(textarea) {
console.log("TextareaAutoResize called for:", textarea.name || textarea.id);