mysterious-toddler-20573
11/13/2021, 1:23 AMuser
11/13/2021, 12:10 PMproud-librarian-99598
11/13/2021, 12:38 PMuser
11/13/2021, 12:39 PMlemon-carpenter-66863
11/13/2021, 1:59 PMadamant-exabyte-92636
11/13/2021, 2:09 PMic-on-success attribute that you could use to trigger client-side stuff on a successful ajax request (post/get/whatever). What we've been doing thus far with htmx is to use hyperscript to list for the htmx:afterRequest event and then check if the xhr.status == 200 . This leads to lots of hyperscript attributes that look like this: _="on htmx:afterRequest(xhr) if xhr.status == 200 then ... else ..." This seem unnecessarily clunky in my mind. I guess what I'm after is an htmx event that gets fired during the ajax response processing cycle, which already does the xhr.status == 200 check (or I guess technically xhr.status >= 200 && xhr.status < 400) ... is there such an event or am I just being blind? If not, do you think it makes sense to add such an event?adamant-exabyte-92636
11/13/2021, 2:13 PMic-on-error equivalent) couldn't hurt either.. 'cause it's not obvious to me that a direct equivalent htmx event exists for that either?mysterious-toddler-20573
11/13/2021, 3:05 PMadamant-exabyte-92636
11/13/2021, 3:07 PMic-action)mysterious-toddler-20573
11/13/2021, 3:08 PMadamant-exabyte-92636
11/13/2021, 3:11 PMhandleAjaxResponse function?mysterious-toddler-20573
11/13/2021, 3:43 PMmysterious-toddler-20573
11/13/2021, 3:43 PMadamant-exabyte-92636
11/13/2021, 3:48 PMhtmx:responseError is perfect. Thanks! I reckon just an equivalent "success" event (perhaps htmx:responseSuccess ?) will do the trick. We want to get it regardless of swapping.. i.e. triggered probably before the swap processing startsadamant-exabyte-92636
11/13/2021, 3:52 PM_="on htmx:responseSuccess doSomeSuccessfulThing() end on htmx:responseError handleTheError() end on htmx:afterRequest doSomeStuffRegardlessOfSuccessOrError()"adamant-exabyte-92636
11/13/2021, 3:52 PMadamant-exabyte-92636
11/13/2021, 3:59 PM_="on htmx:afterRequest(xhr) doSomeStuffRegardlessOfSuccessOrError() then if xhr.status == 200 doSomeSuccessfulThing() else handleTheError()"adamant-exabyte-92636
11/13/2021, 4:02 PMmysterious-toddler-20573
11/13/2021, 5:18 PMcareful-room-54859
11/14/2021, 5:05 AMactive class of another set of elements somewhere else in the DOM? The example you provided is great but I have both a side nav and a breadcrumb nav and they both need to be in sync.careful-room-54859
11/14/2021, 5:30 AMhtml
<div id="breadcrumbs"
class="-intro-x breadcrumb mr-auto hidden sm:flex"
_="on click take .{'side-menu--active'} from <a/> in #side-menu for me@data-target">
<a hx-get="{% url 'landing-page' %}"
hx-target="#viewport"
hx-swap="innerHTML"
hx-push-url="true"
hx-indicator="#content-loader"
class="cursor-pointer"
data-target="#dashboard"
>
Application
</a>
...
</div> I am trying to use data-target as a dynamic target in my side menu.careful-room-54859
11/14/2021, 5:30 AMeager-tiger-27508
11/14/2021, 8:41 AMmysterious-toddler-20573
11/15/2021, 3:44 AMon click
take .{'side-menu--active'}
from <a/> in #side-menu
for #{@data-target}mysterious-toddler-20573
11/15/2021, 3:45 AMmysterious-toddler-20573
11/15/2021, 3:45 AMmysterious-toddler-20573
11/15/2021, 3:46 AM#{} is the way to gomysterious-toddler-20573
11/15/2021, 3:46 AMcareful-room-54859
11/15/2021, 4:13 AMdata-target attribute? Is there something else I need?careful-room-54859
11/15/2021, 4:23 AMhtml
_="on click take .{'side-menu--active'} from <a/> in #side-menu for #{event.target@data-target}"