melodic-france-58143
10/18/2022, 11:59 PMbitter-machine-55943
10/19/2022, 3:23 AMhx-swap-oob
option to tack on CSS/JS imports to the parent <head>
enables a decent component-based approach.proud-librarian-99598
10/19/2022, 2:20 PMhtmx:beforeSwap
event listener. I know in my case that the tooltip is part of the <tr>
element that will be swapped (On of the many rows that could get swapped). So I check for that and hide the correct one:
document.addEventListener('htmx:beforeSwap', ev => {
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
const elementToBeSwapped = ev.detail.target;
for (const tooltipTriggerListElement of tooltipTriggerList) {
const rowElementOfTooltip = tooltipTriggerListElement.closest('tr');
// To avoid that a tooltip remains stuck because the HTML that it refers
// to is swapped out for new html, we need to hide the tooltip.
if( elementToBeSwapped === rowElementOfTooltip) {
bootstrap.Tooltip.getInstance(tooltipTriggerListElement).hide();
}
}
});
It is also important to not use new bootstrap.Tooltip(..)
, but bootstrap.Tooltip.getOrCreateInstance(..
so already initialized tooltips is not initialized again. (I am inializing from htmx.onLoad(function (element) {...})
so that swapped in tooltips will also work.white-motorcycle-95262
10/19/2022, 3:46 PMproud-librarian-99598
10/19/2022, 8:23 PMhtmx.onLoad()
, but there is a noticiable, visible change happening. I have simulated this at https://codepen.io/wimdeblauwe/pen/eYrwZgv for those that want to have a look. Just select a different date, and you will notice the flash.
Interestingly,, I had to do some funky stuff to simulate it with demo.htmx.org, because flatpickr already initialized the date picker in the <template>
that simulated the server response.
Is there a possibility to temporarily mount something in the dom, non-visible and only swap after some callback was called where I could run the flatpickr initialization code to avoid that flicker?mysterious-toddler-20573
10/19/2022, 9:16 PMmelodic-france-58143
10/20/2022, 12:06 AMcuddly-keyboard-70746
10/20/2022, 12:58 AMmysterious-toddler-20573
10/20/2022, 1:55 AMcuddly-keyboard-70746
10/20/2022, 2:52 AMmelodic-france-58143
10/20/2022, 4:29 AMbored-window-42314
10/20/2022, 6:00 AMproud-librarian-99598
10/20/2022, 6:14 AMbored-window-42314
10/20/2022, 6:14 AMproud-librarian-99598
10/20/2022, 7:37 AMhtmx:beforeSwap
, it seems that event.detail.target
contains the HTML element that will be swapped out. Would it be possible to get a reference to the element that will be swapped in in that callback? That might enable that I can initialize some html element before it get's swapped in by running some JavaScript and thus avoid flickering. Not sure if that is possible before it is actually on the page, but I would like to try it. Any idea how I could do this?mammoth-family-48524
10/20/2022, 9:12 AMproud-librarian-99598
10/20/2022, 9:13 AMtall-dinner-62086
10/20/2022, 9:21 AMhtmx:afterProcessNode
instead to add stuff to the node after it's created and processed by htmx?proud-librarian-99598
10/20/2022, 9:53 AMtall-dinner-62086
10/20/2022, 9:55 AMproud-librarian-99598
10/20/2022, 10:02 AMancient-shoe-86801
10/20/2022, 10:05 AMhidden
attribute of the element?ancient-shoe-86801
10/20/2022, 10:06 AMproud-librarian-99598
10/20/2022, 10:12 AMproud-librarian-99598
10/20/2022, 10:13 AMfew-vegetable-15970
10/20/2022, 10:48 AMthankful-apartment-66679
10/20/2022, 2:12 PMfew-vegetable-15970
10/20/2022, 2:39 PMprehistoric-wolf-75047
10/20/2022, 3:49 PM<form hx-get="" hx-trigger="every 10s">
from firing if the form has been interacted with in the last few seconds?broad-lifeguard-12969
10/20/2022, 4:14 PM