mysterious-toddler-20573
12/01/2022, 1:43 AMgreen-activity-6102
12/01/2022, 1:43 AMmysterious-toddler-20573
12/01/2022, 1:43 AMgreen-activity-6102
12/01/2022, 1:43 AMgreen-activity-6102
12/01/2022, 1:44 AMmysterious-toddler-20573
12/01/2022, 2:19 AMgreat-lifeguard-29000
12/01/2022, 5:21 AMgreat-lifeguard-29000
12/01/2022, 5:24 AMthankful-addition-60522
12/01/2022, 7:15 AMthankful-addition-60522
12/01/2022, 7:16 AMthankful-addition-60522
12/01/2022, 8:41 AMblue-gold-89534
12/01/2022, 9:21 AMhtml
<tbody hx-get="{% url 'list' %}"
hx-target="#List"
hx-swap="outerHTML"
hx-trigger="every 30s">
...</tbody>
and in this table I can on click inline edit - but if I need longer than 30secs, I end up with the complete table again. Would be super smart to exclude the line I am working on from the swap, I know. But this sounds like it would blow up the whole logic. Is there a simpler way, for example to "stop" the trigger? With some JS (🤮 ) I could just delete the hx-trigger while an inline is open and add it afterwards. But is there a better way to do it?bitter-carpet-58319
12/01/2022, 9:40 AMbitter-carpet-58319
12/01/2022, 9:41 AMbitter-carpet-58319
12/01/2022, 9:45 AMblue-gold-89534
12/01/2022, 9:48 AM<tbody>
now looks like this:
html
<tbody id="listbody"
hx-get="{% url 'list' %}"
hx-target="#List"
hx-swap="outerHTML"
hx-trigger="every 30s">
...</tbody>
and the edit button got a onclick="toggleHxTrigger('False')
property.
js
function toggleHxTrigger (arg) {
if (arg === "False") {
document.getElementById("listbody").removeAttribute("hx-trigger");
} else {
document.getElementById("listbody").setAttribute("hx-trigger", "every 30s")
}
};
But this does not interrupt the load, Altough I can see in the webdev console that the hx-trigger
is not part of tbody
anymore after clicking.melodic-advantage-28381
12/01/2022, 9:55 AMhx-trigger
once and then launches a setInterval()
. So you can't stop it without custom JS, and even that will be tricky to write, because you need the interval ID (cf https://developer.mozilla.org/en-US/docs/Web/API/setInterval), which is probably kept private by htmx.blue-gold-89534
12/01/2022, 9:57 AMblue-gold-89534
12/01/2022, 9:57 AMripe-action-67367
12/01/2022, 10:00 AMripe-action-67367
12/01/2022, 10:01 AMripe-action-67367
12/01/2022, 10:03 AMevery 1s [!document.querySelectorAll('.editor').length]
like that, but this is straight up uglymelodic-advantage-28381
12/01/2022, 10:05 AM286
(what is that?), a function named cancelPolling
is called. Probably you can hook a tiny JS event listener when your editor opens to call that directly, passing the <tbody>
as the parameter.blue-gold-89534
12/01/2022, 10:06 AMblue-gold-89534
12/01/2022, 10:09 AMevery 30s
in place, then click on edit:
- line in the table gets swapped out
- some JS adds a flag to my hx-get
that indicates, the server should return a status code 286
- when edit line is closed remove that flag?melodic-advantage-28381
12/01/2022, 10:12 AMblue-gold-89534
12/01/2022, 10:13 AMblue-gold-89534
12/01/2022, 10:22 AMripe-action-67367
12/01/2022, 10:23 AMripe-action-67367
12/01/2022, 10:24 AM