eager-psychiatrist-68229
02/12/2023, 8:23 AMcrooked-winter-42525
02/12/2023, 1:43 PMmammoth-airplane-32618
02/12/2023, 2:56 PMhtml
<form class="col-3 col-md text-dark" hx-get="{% url 'vendors' %}" hx-target="body">
<label for="id_name" class="text-white">Search</label>
<p class="text-black">{{ filter_form.form.name }}</p>
<div id="accordion" class="text-dark">
<div class="card">
<div class="card-header" id="headingOne">
<h5 class="mb-0">
<button class="btn btn-link" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne"> <!-- I don't want this performing any HTMX -->
Store Location
</button>
</h5>
</div>
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
<div class="card-body">
{{ filter_form.form.store_location }}
</div>
</div>
</div>
...
<input type="submit" id="testsubmit"/>
</form>
mammoth-airplane-32618
02/12/2023, 3:15 PMbrainy-grass-55742
02/13/2023, 10:10 PMraise BadRequest("Custom message")
. I am able to "catch" the error in htmx by listening to htmx:responseError
how can I access that exact exception message so I can display it?bitter-monkey-50309
02/13/2023, 10:22 PMreturn HttpResponseBadRequest("Invalid state")
brainy-grass-55742
02/13/2023, 10:54 PMHttpResponseBadRequest
or HttpResponse(status_code=400)
is that HTMX is likely to process both responses as status: 200 statusText: "OK"
even though response: "<HttpResponseBadRequest status_code=400, \"text/html; charset=utf-8\">"
when you listen to 'htmx:afterRequest'
event.
Raising BadRequest
on the other hand gives the appropriate status code, 400
when you listen to 'htmx:responseError'
event, as it should be, but then the custom message is not sent along, even when you specify one when you raised it.brainy-grass-55742
02/13/2023, 10:55 PMbitter-monkey-50309
02/13/2023, 11:01 PM200
if the HTTP status code isn't. At least I'm pretty sure it doesn't when I've done similar before, though that was a while ago and on work project's I can't look at right now and I've not bothered to do much error handling in my personal ones (yet)bitter-monkey-50309
02/13/2023, 11:02 PMHX-Trigger
in certain error scenarios to trigger some JS that renders a toast notification with an error if need be. Bonus is it can also be used to show on success, close modals, etc.brainy-grass-55742
02/13/2023, 11:10 PMHX-Triggers
. As in the case you described above, I'm using this for error messages.eager-psychiatrist-68229
02/14/2023, 7:02 AMeager-psychiatrist-68229
02/14/2023, 7:03 AMgray-rocket-3571
02/14/2023, 10:26 PMbrainy-grass-55742
02/14/2023, 11:56 PMgorgeous-photographer-36571
02/15/2023, 6:19 PMgorgeous-photographer-36571
02/15/2023, 6:24 PMmysterious-toddler-20573
02/15/2023, 9:08 PMaloof-crayon-56651
02/16/2023, 7:45 AMaloof-crayon-56651
02/16/2023, 7:45 AMaloof-crayon-56651
02/16/2023, 8:54 AMgorgeous-photographer-36571
02/16/2023, 1:07 PMgorgeous-photographer-36571
02/16/2023, 1:08 PMpython
# Initialize response
response = HttpResponse(status=200)
# Trigger client event to update table
trigger_client_event(response, "requisitionChanged", params={}, after='swap')
# Trigger client event to close modal
trigger_client_event(response, "closeModal", params={}, after='settle')
# Return response
return response
gorgeous-photographer-36571
02/16/2023, 1:11 PMaloof-crayon-56651
02/16/2023, 7:07 PMgorgeous-photographer-36571
02/16/2023, 9:08 PMgorgeous-photographer-36571
02/16/2023, 9:10 PMaloof-crayon-56651
02/16/2023, 9:56 PMaloof-crayon-56651
02/16/2023, 9:57 PMaloof-crayon-56651
02/16/2023, 9:59 PMon click remove my innerHTML
doesn't work. on click set my innerHTML to ''
works, though.