Skip to content

Commit

Permalink
Update hx-trigger.md (#3076)
Browse files Browse the repository at this point in the history
* Update hx-trigger.md

- Added a clarification in notes to suggest adding a delay when adding reset to hx-trigger.

- Also thought it's useful to add a reference to MDN's list of web API  events, as it was one of the omissions in the hx-trigger doc which made me Google a little when I started out.

* Update hx-trigger.md

My bad, you're absolutely right. I've rewritten the proposed changes with your explanation in mind.
  • Loading branch information
zachczx authored Dec 15, 2024
1 parent 44af27f commit b3d3569
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions www/content/attributes/hx-trigger.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ value can be one of the following:

### Standard Events

Standard events refer to [web API events](https://developer.mozilla.org/en-US/docs/Web/API/Element#events) (e.g. click, keydown, mouseup, load).

A standard event, such as `click` can be specified as the trigger like so:

```html
Expand Down Expand Up @@ -155,3 +157,4 @@ The AJAX request can be triggered via JavaScript [`htmx.trigger()`](@/api.md#tri
* `hx-trigger` is not inherited
* `hx-trigger` can be used without an AJAX request, in which case it will only fire the `htmx:trigger` event
* In order to pass a CSS selector that contains whitespace (e.g. `form input`) to the `from`- or `target`-modifier, surround the selector in parentheses or curly brackets (e.g. `from:(form input)` or `from:closest (form input)`)
* A reset event in hx-trigger (e.g. hx-trigger="change, reset") might not work as intended, since HTMX builds its values and sends a request before the browser resets the form values. As a workaround, add a delay to let the browser reset the form before making the request (e.g. hx-trigger="change, reset delay:0.01s").

0 comments on commit b3d3569

Please sign in to comment.