Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple triggers for HTMX?

Is it possible to enable multiple trigger types for HTMX? What I want to do is to trigger HTMX on either content change or page load. So far, if I include both trigger types in hx-trigger, only the first trigger is executed; so in the example below, HTMX is triggered only upon content change.

<select name="area" id="area" hx-post="/api/search" hx-trigger="change load" hx-target="#neighborhood" class="block">
  <option>eby</option>
  <option>nby</option>
  <option>pen</option>
  <option>sfc</option>
  <option>scz</option>
  <option>sby</option>
</select>
like image 519
irahorecka Avatar asked Jan 25 '23 07:01

irahorecka


1 Answers

It's as simple as comma-separating your trigger types:

<select name="area" id="area" hx-post="/api/search" hx-trigger="change, load" hx-target="#neighborhood" class="block">
  <option>eby</option>
  <option>nby</option>
  <option>pen</option>
  <option>sfc</option>
  <option>scz</option>
  <option>sby</option>
</select>
like image 87
irahorecka Avatar answered Jan 31 '23 20:01

irahorecka