mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 09:28:38 -06:00
Fixes #8134: reinitialize event listeners when HTMX swaps elements
This commit is contained in:
parent
8e95ac42c2
commit
373cc74a33
@ -5,6 +5,7 @@
|
|||||||
### Enhancements
|
### Enhancements
|
||||||
|
|
||||||
* [#8100](https://github.com/netbox-community/netbox/issues/8100) - Add "other" choice for FHRP group protocol
|
* [#8100](https://github.com/netbox-community/netbox/issues/8100) - Add "other" choice for FHRP group protocol
|
||||||
|
* [#8134](https://github.com/netbox-community/netbox/issues/8134) - Fix issue where HTMX-swapped UI elements needed to be reinitialized
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|
||||||
|
BIN
netbox/project-static/dist/netbox.js
vendored
BIN
netbox/project-static/dist/netbox.js
vendored
Binary file not shown.
BIN
netbox/project-static/dist/netbox.js.map
vendored
BIN
netbox/project-static/dist/netbox.js.map
vendored
Binary file not shown.
23
netbox/project-static/src/htmx.ts
Normal file
23
netbox/project-static/src/htmx.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { getElements, isTruthy } from './util';
|
||||||
|
import { initButtons } from './buttons';
|
||||||
|
|
||||||
|
function initDepedencies(): void {
|
||||||
|
for (const init of [initButtons]) {
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook into HTMX's event system to reinitialize specific native event listeners when HTMX swaps
|
||||||
|
* elements.
|
||||||
|
*/
|
||||||
|
export function initHtmx(): void {
|
||||||
|
for (const element of getElements('[hx-target]')) {
|
||||||
|
const targetSelector = element.getAttribute('hx-target');
|
||||||
|
if (isTruthy(targetSelector)) {
|
||||||
|
for (const target of getElements(targetSelector)) {
|
||||||
|
target.addEventListener('htmx:afterSettle', initDepedencies);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -12,6 +12,7 @@ import { initInterfaceTable } from './tables';
|
|||||||
import { initSideNav } from './sidenav';
|
import { initSideNav } from './sidenav';
|
||||||
import { initRackElevation } from './racks';
|
import { initRackElevation } from './racks';
|
||||||
import { initLinks } from './links';
|
import { initLinks } from './links';
|
||||||
|
import { initHtmx } from './htmx';
|
||||||
|
|
||||||
function initDocument(): void {
|
function initDocument(): void {
|
||||||
for (const init of [
|
for (const init of [
|
||||||
@ -29,6 +30,7 @@ function initDocument(): void {
|
|||||||
initSideNav,
|
initSideNav,
|
||||||
initRackElevation,
|
initRackElevation,
|
||||||
initLinks,
|
initLinks,
|
||||||
|
initHtmx,
|
||||||
]) {
|
]) {
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user