panel: show/hide rules reach a form that arrives in an htmx swap

initShowWhen bound a change listener to each control it found at DOMContentLoaded, so a form swapped in later would have been neither synced nor wired. The rules now listen once on the document and are applied again on htmx:load. No form arrives by a swap today; the roadmap row that recorded the gap is struck.

Checked in a browser on the application form: the rate-limit select toggles the manual and auto fields as before, and a copy of the form put into the page with htmx.swap is synced on arrival and follows its select. go vet and go test ./internal/web/... pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mix
2026-10-11 00:31:36 +03:00
co-authored by Claude Opus 5.5
parent c5588ebba1
commit bbd2d83364
2 changed files with 16 additions and 7 deletions
+15 -6
View File
@@ -153,19 +153,28 @@
function initShowWhen(root) {
showWhenRules.forEach(function (rule) {
root.querySelectorAll(rule.match).forEach(function (control) {
syncShowWhen(control);
control.addEventListener("change", function () {
syncShowWhen(control);
});
});
root.querySelectorAll(rule.match).forEach(syncShowWhen);
});
}
// One listener for the document rather than one per control: a form that
// arrives in an htmx swap is covered without being wired up again.
document.addEventListener("change", function (ev) {
if (ev.target && ev.target.matches) {
syncShowWhen(ev.target);
}
});
document.addEventListener("DOMContentLoaded", function () {
initShowWhen(document);
});
// htmx:load fires for every element htmx puts into the page, so swapped-in
// markup starts with its blocks shown or hidden the way a full page does.
document.addEventListener("htmx:load", function (ev) {
initShowWhen(ev.detail.elt);
});
// --- Adaptive monitoring polling ---------------------------------------
// The four monitoring fragments carry data-poll and hx-trigger="load" for
// the first fetch only. panel.js schedules the rest: 5 s while the operator