Bulk Update

이 데λͺ¨λŠ” 행을 μ„ νƒν•œ ν›„ 일괄 μ—…λ°μ΄νŠΈν•˜λŠ” 일반적인 νŒ¨ν„΄μ„ κ΅¬ν˜„ν•˜λŠ” 방법을 λ³΄μ—¬μ€λ‹ˆλ‹€. μ΄λŠ” ν…Œμ΄λΈ” μ£Όμœ„μ— form을 λ°°μΉ˜ν•˜κ³ , ν…Œμ΄λΈ” μ•ˆμ— μ²΄ν¬λ°•μŠ€λ₯Ό λ„£κ³ , 체크된 값을 form 제좜(POST μš”μ²­)에 ν¬ν•¨μ‹œμΌœ μˆ˜ν–‰λ©λ‹ˆλ‹€:

<form id="checked-contacts"
      hx-post="/users"
      hx-swap="outerHTML settle:3s"
      hx-target="#toast">
    <table>
      <thead>
      <tr>
        <th>Name</th>
        <th>Email</th>
        <th>Active</th>
      </tr>
      </thead>
      <tbody id="tbody">
        <tr>
          <td>Joe Smith</td>
          <td>joe@smith.org</td>
          <td><input type="checkbox" name="active:joe@smith.org"></td>
        </tr>
        ...
      </tbody>
    </table>
    <input type="submit" value="Bulk Update" class="btn primary">
    <span id="toast"></span>
</form>

μ„œλ²„λŠ” μ²΄ν¬λ°•μŠ€μ˜ 값에 따라 μƒνƒœλ₯Ό 일괄 μ—…λ°μ΄νŠΈν•©λ‹ˆλ‹€. μ„œλ²„λŠ” μ—…λ°μ΄νŠΈμ— λŒ€ν•œ μž‘μ€ ν† μŠ€νŠΈ λ©”μ‹œμ§€λ‘œ μ‘λ‹΅ν•˜μ—¬ μ‚¬μš©μžμ—κ²Œ μ•Œλ¦¬κ³ , 접근성을 μœ„ν•΄ ARIAλ₯Ό μ‚¬μš©ν•˜μ—¬ μ—…λ°μ΄νŠΈλ₯Ό κ³΅μ†ν•˜κ²Œ μ•Œλ¦½λ‹ˆλ‹€.

#toast.htmx-settling {
  opacity: 100;
}

#toast {
  background: #E1F0DA;
  opacity: 0;
  transition: opacity 3s ease-out;
}

ν₯미둜운 점은 HTML form μž…λ ₯이 이미 자체 μƒνƒœλ₯Ό κ΄€λ¦¬ν•˜κΈ° λ•Œλ¬Έμ— μ‚¬μš©μž ν…Œμ΄λΈ”μ˜ 일뢀λ₯Ό λ‹€μ‹œ λ Œλ”λ§ν•  ν•„μš”κ°€ μ—†λ‹€λŠ” κ²ƒμž…λ‹ˆλ‹€. ν™œμ„± μ‚¬μš©μž μ²΄ν¬λ°•μŠ€λŠ” 이미 μ²΄ν¬λ˜μ–΄ 있고, λΉ„ν™œμ„± μ‚¬μš©μž μ²΄ν¬λ°•μŠ€λŠ” 체크 ν•΄μ œλ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€!

μ•„λž˜μ—μ„œ 이 μ½”λ“œμ˜ μž‘λ™ 예제λ₯Ό 확인할 수 μžˆμŠ΅λ‹ˆλ‹€.

Server Requests ↑ Show

πŸ”—Demo