gentle-notebook-11755
10/19/2021, 2:42 AMsparse-musician-64201
10/19/2021, 4:57 AMsparse-musician-64201
10/19/2021, 4:58 AMadamant-exabyte-92636
10/19/2021, 7:37 AM<form id="myform" hx-trigger="submit[$(target).valid()]" ... > the slight benefit being you don't need to trigger custom events, since you're just directly wiring in the jquery.validate valid() call to be made when the normal submit event is fired on the formbillions-microphone-84331
10/19/2021, 7:51 AMdocument.body.addEventListener('htmx:beforeSwap', function(event) {
var status = event.detail.xhr.status
// allow to swap on certain http codes when
// the error is rendered from the server
if ([422, 409].includes(status)) {
event.detail.shouldSwap = true
}
// flash if other error
if (!event.detail.shouldSwap && status >= 400 && status < 600) {
document.getElementById("flash").innerHTML = '<p>{{ "An error has occurred" | translate }}</p>'
}
})ancient-diamond-23303
10/19/2021, 8:07 AM<div _="on error call alert('Oops! Something went wrong')" hx-get="/some_route">
You can also pass messages (like the code) in the HX-Trigger headerbillions-microphone-84331
10/19/2021, 8:26 AMbillions-microphone-84331
10/19/2021, 8:28 AMancient-diamond-23303
10/19/2021, 8:43 AM<div id="flash-message" hx-swap-oob="true"></div>
and everytime there is an error I send a partial template with the same container but including the error inside. Then htmx will replace the previous container with the new container.billions-microphone-84331
10/19/2021, 8:49 AMtall-cat-32859
10/19/2021, 9:05 AMuser
10/19/2021, 12:31 PMgorgeous-ghost-95789
10/19/2021, 12:34 PMgorgeous-ghost-95789
10/19/2021, 12:36 PM<form hx-post=“/myserver” hx-trigger=“on change from:find #radioid”>user
10/19/2021, 12:41 PMgorgeous-ghost-95789
10/19/2021, 12:44 PMancient-diamond-23303
10/19/2021, 12:55 PM<form hx-post=“/myserver” hx-trigger=“change from:#radioid”>gorgeous-ghost-95789
10/19/2021, 12:57 PMmysterious-toddler-20573
10/19/2021, 1:35 PMhtml
<form hx-post="/myserver" hx-trigger="change from:#radioid">
....
</form>user
10/19/2021, 1:44 PMgentle-notebook-11755
10/19/2021, 1:56 PMuser
10/19/2021, 5:08 PMmysterious-toddler-20573
10/19/2021, 5:14 PMhx-get on the option itself?mysterious-toddler-20573
10/19/2021, 5:14 PMmysterious-toddler-20573
10/19/2021, 5:15 PMmysterious-toddler-20573
10/19/2021, 5:16 PMhtml
<form hx-boost="true" ... >
...
<label for="cars">Choose a car:</label>
<select id="cars" hx-get="/car-details" hx-target=#something-else">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
...
</form>mysterious-toddler-20573
10/19/2021, 5:17 PMmysterious-toddler-20573
10/19/2021, 5:17 PMuser
10/19/2021, 5:17 PMuser
10/19/2021, 5:18 PM