coverup

Confirm dialog

Replaces the browser confirm(). Works with hx-confirm out of the box.

With hx-confirm

Add hx-confirm to any htmx element. Coverup intercepts it and shows the styled dialog; the request fires only after the user confirms. Optional data-confirm-message, data-confirm-label and data-confirm-tone="neutral".

Ada Lovelace
Grace Hopper
<table class="tbl" style="max-width:520px">
  <tbody id="confirm-demo">
    <tr><td>Ada Lovelace</td><td style="text-align:right"><button class="btn btn-ghost btn-sm" hx-delete="/api/users/1" hx-confirm="Delete Ada Lovelace?" data-confirm-message="This can't be undone." hx-target="closest tr" hx-swap="outerHTML swap:150ms"><svg class="i i-sm"><use href="#i-trash"/></svg>Delete</button></td></tr>
    <tr><td>Grace Hopper</td><td style="text-align:right"><button class="btn btn-ghost btn-sm" hx-delete="/api/users/2" hx-confirm="Delete Grace Hopper?" data-confirm-message="This can't be undone." hx-target="closest tr" hx-swap="outerHTML swap:150ms"><svg class="i i-sm"><use href="#i-trash"/></svg>Delete</button></td></tr>
  </tbody>
</table>

From JavaScript

<button class="btn" id="confirm-js">Discard draft</button>
<script>
  document.getElementById('confirm-js').onclick = function () {
    Coverup.confirm({
      title: 'Discard this draft?',
      message: 'Your edits will be lost.',
      confirmLabel: 'Discard',
      tone: 'danger' // or 'neutral'
    }).then(function (ok) { if (ok) Coverup.toast({ type: 'ok', title: 'Draft discarded' }); });
  };
</script>

Classes

SelectorPurpose
hx-confirm="Question?"Becomes a styled dialog
data-confirm-message / -label / -toneOptional copy and tone (danger or neutral)
Coverup.confirm(opts)Returns Promise