AHA demos
← All demos

Active search

Search the list of htmx attributes. Every keystroke (after a short pause) asks the server, and the server answers with table rows.

Searching…

hx-getIssue a GET request to the given URL
hx-postIssue a POST request to the given URL
hx-putIssue a PUT request to the given URL
hx-patchIssue a PATCH request to the given URL
hx-deleteIssue a DELETE request to the given URL
hx-triggerWhich event fires the request, with modifiers like delay and changed
hx-targetWhich element receives the response
hx-swapHow the response is swapped in: innerHTML, outerHTML, beforeend...
hx-swap-oobSwap this element into the page by id, out of band
hx-selectPick a part of the response to swap
hx-select-oobPick parts of the response to swap out of band
hx-valsAdd extra values to the request
hx-includeInclude values from other elements in the request
hx-indicatorElement that gets the htmx-request class while loading
hx-confirmAsk for confirmation before the request
hx-promptAsk for a value before the request
hx-boostTurn links and forms into AJAX requests
hx-push-urlPush a URL into browser history
hx-replace-urlReplace the current URL in browser history
hx-syncCoordinate requests between elements
hx-disableDisable elements while a request is in flight
hx-preserveKeep an element as is across swaps
hx-headersAdd headers to the request
hx-on:*Run inline JavaScript on any event
hx-configPer-element configuration
hx-status:*Override the swap for a given response status
hx-partialA tag that wraps content and says where it goes. New in htmx 4
hx-ignoreTell htmx to leave this subtree alone
hx-preloadPreload a request before the user triggers it
hx-history-eltElement to snapshot for history

What to look at

hx-trigger="input changed delay:300ms" is the whole debounce. No timer code. htmx waits 300ms after the last keystroke and only sends the request if the value changed.

hx-indicator points at the "Searching…" text. htmx adds the htmx-request class to it while a request is in flight. A CSS rule does the rest.

The Clear button is Alpine and htmx on the same element. Alpine shows it only when there is text (x-show="q") and empties the input. htmx fetches the full list again.

The same Astro component renders the results on first load and in the API response. One template, used twice.

Source

Loading source…

Every file of this demo, as it runs. Or browse it on GitHub ↗