late-shampoo-89851
05/25/2022, 2:38 PMhtml
<button class="ml-3 button-nav button-tertiary"
hx-get="{% url 'listings:hx_list' %}"
hx-swap="innerHTML" hx-target="#list"
hx-trigger="myEvent from:body">
Next
</button>
<script>
document.body.addEventListener("myEvent", function(evt){
alert("myEvent was triggered!");
})
</script>
The request works fine, but once I add the hx-trigger, nothing happens (no request nor alert). What am I missing?hundreds-camera-24900
05/25/2022, 2:40 PMhundreds-camera-24900
05/25/2022, 2:40 PMlate-shampoo-89851
05/25/2022, 2:42 PMhundreds-camera-24900
05/25/2022, 3:02 PMhundreds-camera-24900
05/25/2022, 3:02 PMhundreds-camera-24900
05/25/2022, 3:02 PMhundreds-camera-24900
05/25/2022, 3:03 PMmysterious-toddler-20573
05/25/2022, 3:12 PMcareful-room-54859
05/25/2022, 4:12 PM/custom-route?hx-refresh=true
...
In JavaScript or Hyperscript...
Check for the query param and then
location.reload();breezy-diamond-95556
05/25/2022, 4:49 PMmysterious-toddler-20573
05/25/2022, 8:49 PMHX-Redirect response header will issue a full, clientside requestcareful-room-54859
05/25/2022, 9:10 PMhundreds-camera-24900
05/26/2022, 12:57 AMhundreds-camera-24900
05/26/2022, 12:58 AMcareful-room-54859
05/26/2022, 3:56 AMcalm-queen-64495
05/26/2022, 10:13 AMtall-dinner-62086
05/26/2022, 10:32 AMcalm-queen-64495
05/26/2022, 12:08 PMtall-dinner-62086
05/26/2022, 1:44 PMworried-hair-75253
05/26/2022, 3:27 PMcalm-queen-64495
05/26/2022, 3:56 PMworried-hair-75253
05/26/2022, 3:57 PMworried-hair-75253
05/26/2022, 3:57 PMworried-hair-75253
05/26/2022, 3:58 PMdocument.body.addEventListener('htmx:afterSwap', function (evt) {
if (evt.detail.elt.id.includes("Content")) {
sortTable.init();
}
else {
var targ = evt.detail.elt.offsetParent;
if (targ) {
var col = targ.className.match(/js-sort-\d+/);
if (col) {
var colNum; if (col) { colNum = col[0].replace(/js-sort-/, "") }
var dir = targ.className.match(/js-sort-(a|de)sc/);
var direction = "asc"; if (dir) { direction = dir[0].replace(/js-sort-/, ""); }
if (colNum) {
sortTable(targ, colNum, direction);
}
}
}
}
});calm-queen-64495
05/26/2022, 4:05 PMhtml
<table class="table my-0 dashboard" id="task-table">
<thead class="active-claim-table-head">
<tr>
<th>Repairer</th>
<th>REGO</th>
<th>Client Name</th>
<th>Task</th>
<th>Action</th>
</tr>
</thead>
<tbody hx-get="{% url 'admin-list-all-tasks'%}" hx-trigger="load, taskListUpdated from:body" id='task-table-body'>
</tbody>
</table>calm-queen-64495
05/26/2022, 4:05 PMworried-hair-75253
05/26/2022, 4:07 PMcalm-queen-64495
05/26/2022, 4:09 PM