mysterious-toddler-20573
12/01/2022, 2:54 PMfreezing-waitress-26396
12/01/2022, 2:55 PMwhite-motorcycle-95262
12/01/2022, 4:15 PMhx-get
), the screen scrolls down a bit. I don't have show:
or scroll:
set on the element (or parents), and even when I add scroll:window:top
to the hw-swap
it still happens. I thought it was related to the first form field having autofocus
, but I disabled that and it still does it.
EDIT: I also checked htmx.config.defaultFocusScroll
in the console and it's false
late-king-98305
12/01/2022, 7:33 PMthankful-addition-60522
12/01/2022, 7:34 PMsalmon-oil-67352
12/01/2022, 7:56 PMconst modal = new bootstrap.Modal(document.getElementById('generic_modal_placeholder'))
htmx.on('htmx:beforeSwap', (event) => {
if (event.detail.target.id == 'main_content') {
modal.hide()
}
})
This works fine but sometimes the target of the request is not "main_content". Is there a way to add in the response, something to tell HTMX to close the modal.
Example:
if (event.detail.close_modal == "True") {
modal.hide()
}
Is there a way to piggy back data from the backend, so that the event handler can pick it up?mysterious-toddler-20573
12/01/2022, 8:00 PMHX-Trigger
response header to trigger and event (e.g. closeModal
) and then listen for that event and call modal.hide()salmon-oil-67352
12/01/2022, 8:24 PMresponse = render(request, "product_cost.html", {"product": product})
response.headers["HX-Trigger"] = "close_modal"
return response
Frontend/JS:
document.body.addEventListener("close_modal", function(evt){
modal.hide()
modal_lg.hide()
})
mysterious-toddler-20573
12/01/2022, 8:26 PMsalmon-oil-67352
12/01/2022, 8:26 PMwhite-motorcycle-95262
12/01/2022, 8:31 PMhx-select="#main"
and I don't think there's a way to do that here. Currently my 404 template is just a fragment (e.g., only contains #main), and it works nice with HTMX but when I cold load a 404, I don't get any styles, etc bc the <head>
and nav etc are not included in the 404 template.
Thoughts?
document.addEventListener("htmx:beforeSwap", (event) => {
switch (event.detail.xhr.status) {
case 403:
case 404:
case 500:
event.detail.shouldSwap = true;
event.detail.isError = false;
event.detail.target = htmx.find("#main");
}
});
EDIT: I don't know why I asked this, I just have to make my 404 template conditionally extend my base template, the same way I do every other template π Braindead today.mammoth-family-48524
12/02/2022, 9:21 AMhx-include
works with Shoelace elements if you start the selectors with id's. E.g.
hx-include="#myform sl-input, #myform sl-checkbox, #myform sl-rating"
It doesn't work with find
though. E.g. hx-include="find sl-input, find sl-checkbox, find sl-rating
will only find the sl-input
, not the checkbox and rating, like what you found in your tests. I hope that helps.abundant-spring-38265
12/02/2022, 11:01 AMabundant-spring-38265
12/02/2022, 11:01 AMripe-action-67367
12/02/2022, 11:28 AMabundant-spring-38265
12/02/2022, 11:49 AMancient-shoe-86801
12/02/2022, 5:44 PMancient-shoe-86801
12/02/2022, 5:44 PMwhite-motorcycle-95262
12/02/2022, 6:25 PMdata-bs-toggle="collapse"
. Any suggestions?early-camera-41285
12/03/2022, 12:06 AM.show
(and other things).white-motorcycle-95262
12/03/2022, 12:26 AMmysterious-doctor-98164
12/03/2022, 7:20 AM<form id="myform" hx-include="#myform sl-checkbox" hx-target="#target" hx-post="/endpoint">
<sl-checkbox checked>Check me</sl-checkbox>
<sl-button type="submit">Submit me</sl-button>
</form>
and this sends no data in the request to /endpoint
.
Am I doing something incredibly dumb?mammoth-family-48524
12/03/2022, 7:23 AMmysterious-doctor-98164
12/03/2022, 7:26 AMname="my-checkbox"
to the sl-checkbox
(and the button, for that matter) doesn't seem to change anything, though your point is well taken, there should have been a name on there.mysterious-doctor-98164
12/03/2022, 7:30 AMsl-input
as usual, just not sl-checkbox
or anything like that. name
obviously required.shy-zebra-22292
12/03/2022, 7:40 AMshy-zebra-22292
12/03/2022, 7:45 AMshy-zebra-22292
12/03/2022, 7:47 AMmysterious-doctor-98164
12/03/2022, 7:47 AMmammoth-family-48524
12/03/2022, 8:35 AMvalue
attribute π€·