mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
Fix accordion re-init after HTMX outerHTML swap on repertoire page
The htmx:afterSwap handler was calling initAccordions(e.detail.target) but after an outerHTML swap, e.detail.target references the old detached DOM element, not the new live element. This meant accordion click handlers were never attached to the new filter column toggles after applying or removing a filter — breaking all subsequent interaction. Fix: query the live DOM with document.querySelector() instead.
This commit is contained in:
@@ -96,10 +96,12 @@
|
||||
// Initial bind
|
||||
initAccordions(document);
|
||||
|
||||
// Re-bind after HTMX swaps
|
||||
// Re-bind after HTMX swaps.
|
||||
// Must query the live DOM — e.detail.target is the *old* detached element after outerHTML swaps.
|
||||
document.body.addEventListener('htmx:afterSwap', function (e) {
|
||||
if (e.detail.target && e.detail.target.matches && e.detail.target.matches(INDEX_SEL)) {
|
||||
initAccordions(e.detail.target);
|
||||
var liveIndex = document.querySelector(INDEX_SEL);
|
||||
if (liveIndex) initAccordions(liveIndex);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user