Cascading Selects

이 μ˜ˆμ œμ—μ„œλŠ” ν•œ select의 값이 λ‹€λ₯Έ selectμ—μ„œ μ„ νƒλœ 값에 따라 달라지도둝 λ§Œλ“œλŠ” 방법을 λ³΄μ—¬μ€λ‹ˆλ‹€.

λ¨Όμ € make 선택에 λŒ€ν•΄ κΈ°λ³Έκ°’μœΌλ‘œ Audiλ₯Ό μ„€μ •ν•©λ‹ˆλ‹€. 그런 λ‹€μŒ 이 make에 λŒ€ν•œ model 선택 ν•­λͺ©μ„ λ Œλ”λ§ν•©λ‹ˆλ‹€. make 선택 ν•­λͺ©μ€ models 선택 ν•­λͺ©μ„ λŒ€μƒμœΌλ‘œ /models둜 GET μš”μ²­μ„ νŠΈλ¦¬κ±°ν•˜λ„λ‘ μ„€μ •ν•©λ‹ˆλ‹€.

μ—¬κΈ° μ½”λ“œκ°€ μžˆμŠ΅λ‹ˆλ‹€:

<div>
    <label>Make</label>
    <select name="make" hx-get="/models" hx-target="#models" hx-indicator=".htmx-indicator">
      <option value="audi">Audi</option>
      <option value="toyota">Toyota</option>
      <option value="bmw">BMW</option>
    </select>
  </div>
  <div>
    <label>Model</label>
    <select id="models" name="model">
      <option value="a1">A1</option>
      ...
    </select>
    <img class="htmx-indicator" width="20" src="/img/bars.svg">
</div>

/models μ—”λ“œν¬μΈνŠΈλ‘œ μš”μ²­μ΄ 전솑될 λ•Œ, ν•΄λ‹Ή make에 λŒ€ν•œ λͺ¨λΈμ΄ λ°˜ν™˜λ©λ‹ˆλ‹€.

<option value='325i'>325i</option>
<option value='325ix'>325ix</option>
<option value='X5'>X5</option> 

그리고 model selectμ—μ„œ μ‚¬μš©ν•  수 있게 λ©λ‹ˆλ‹€.

Server Requests ↑ Show

πŸ”—Demo