AHA demos
← All demos

Cascading selects

Pick a country and the city list updates from the server. The classic dependent dropdown, in one attribute.

You picked , .

Pick a city to see a summary.

What to look at

A <select> triggers on change by default. So hx-get="/api/selects/cities" on the country select fires when you pick a country, sends ?country=italy, and swaps the response into the city select.

The server returns a complete <select>. It is the same CitySelect.astro component the page used for the initial render.

Alpine tracks both values with x-model to show the summary. The new city select comes from the server with x-model="city" already on it. Alpine picks it up the moment htmx swaps it in.

Source

Loading source…

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