mysterious-toddler-20573
10/30/2022, 7:16 PMjavascript
document.body.addEventListener('htmx:confirm', function(evt) {
evt.preventDefault();
swal({
title: "Are you sure?",
text: "Are you sure you are sure?",
icon: "warning",
buttons: true,
dangerMode: true,
}).then((confirmed) => {
if (confirmed) {
evt.detail.issueRequest();
}
});
});
bitter-machine-55943
10/30/2022, 8:35 PMmysterious-toddler-20573
10/30/2022, 9:49 PMmysterious-toddler-20573
10/30/2022, 9:50 PMwhite-motorcycle-95262
10/31/2022, 12:12 PMripe-action-67367
10/31/2022, 12:17 PMquiet-television-94579
10/31/2022, 1:32 PMquiet-television-94579
10/31/2022, 1:37 PMcuddly-keyboard-70746
10/31/2022, 1:39 PMripe-action-67367
10/31/2022, 1:47 PMquiet-television-94579
10/31/2022, 1:49 PMripe-action-67367
10/31/2022, 1:49 PMripe-action-67367
10/31/2022, 1:51 PMquiet-television-94579
10/31/2022, 1:52 PMbitter-machine-55943
10/31/2022, 2:01 PMbitter-machine-55943
10/31/2022, 2:02 PMcreateContextualFragment
green-activity-6102
10/31/2022, 2:34 PMhx-target
, eg CSS query selectors. My use case here is that I've got the same button rendered in 2 or more places on the page -- I can use a CSS class like button-{{id}}
to target the both.
frankly i'm a little surprised to see IDs in the hx-swap
tag at all... AFAIK historically that was only ever meant to describe swap strategies and not targetsmysterious-toddler-20573
10/31/2022, 3:33 PMquiet-television-94579
10/31/2022, 4:29 PMastonishing-teacher-48635
10/31/2022, 5:26 PMastonishing-teacher-48635
10/31/2022, 5:26 PMastonishing-teacher-48635
10/31/2022, 5:27 PM<button
hx-get="/test"
hx-ext="htmx-swal2"
hx-swal-confirm='{"title": "Hello world", "text": "Are you sure?", "icon": "success"}'
</button>
mysterious-toddler-20573
10/31/2022, 5:28 PMpreventDefault()
the htmx:confirm
event!astonishing-teacher-48635
10/31/2022, 5:28 PMmysterious-toddler-20573
10/31/2022, 5:28 PMmysterious-toddler-20573
10/31/2022, 5:28 PMastonishing-teacher-48635
10/31/2022, 5:28 PMastonishing-teacher-48635
10/31/2022, 5:28 PMastonishing-teacher-48635
10/31/2022, 5:29 PMif (name == "htmx:confirm") {
evt.preventDefault();
let attrs = JSON.parse(evt.detail.elt.getAttribute("hx-swal-confirm"));
Swal.fire({
title: attrs["title"] || "Are you sure?",
text: attrs["text"],
html: attrs["html"],
icon: attrs["icon"] || "warning",
showCancelButton: true
}).then((obj) => {
if (obj.isConfirmed) {
evt.detail.issueRequest();
}
});
mysterious-toddler-20573
10/31/2022, 5:29 PM