hx-trigger with custom event triggers on other events #3245
-
I'm dispatching an event from an alpine.js component like so: Then I'm using the event as a trigger like this: <div hx-post="/login" hx-trigger="auth from:body" hx-vals="js:{...event.detail}">
<input type="text" hx-post="/check-username" hx-trigger="changed">
</div> The issue is that the input change triggers the parent div hx-vals evaluation; I get an error that 'detail' is undefined. Is this expected? I thought the parent div would only trigger from the "auth" event. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hey, Also, is it expected to use Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
Okay, thanks for the help! |
Beta Was this translation helpful? Give feedback.
Hey,
hx-vals is inherited by default, which is likely why you're getting it evaluated for the child input ; I think that instead of being the parent div that gets its
hx-vals
evaluated, it's simply theinput
that inherits thehx-vals
from its parent div, thus gets its evaluated for itself.I think you could add
hx-vals="unset"
to your input to fix thisAlso, is it expected to use
hx-trigger="changed"
here? You might want to use the standard eventchange
instead, aschanged
is a modifier keyword that htmx supports, but that still has to complement an event nameHope this helps!