Skip to content
Discussion options

You must be logged in to vote

Yes, hx-on can be used there, but there are two gotchas in your example.

First, use the kebab-case htmx event name in attributes. Attribute names are lower-cased by the DOM, so afterRequest is not the safe form. Use after-request, or the htmx shorthand:

<input
  type="search"
  id="exercisesSearch"
  class="search"
  name="q"
  placeholder="Type to search exercises..."
  required
  hx-post="/exercises/search"
  hx-trigger="input changed delay:200ms, search"
  hx-target="#resultsContainer"
  hx-on::after-swap="handleLoad()"
/>

Second, for your use case after-request is probably the wrong lifecycle event. It only tells you the request finished. Since you want to initialize keyboard navigati…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@fullstackplus
Comment options

Answer selected by fullstackplus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants