Typed Confirmation
Require an exact phrase before submitting a destructive action.
HTML
<div class="mero-scope" data-mero-scope>
<button class="mero-button mero-button-danger" type="button" id="confirm-environment-opener" data-mero-open="confirm-environment">Delete environment</button>
<dialog class="mero-dialog" id="confirm-environment" role="alertdialog" data-mero-static aria-labelledby="confirm-environment-title" aria-describedby="confirm-environment-description">
<div class="mero-dialog-body mero-stack">
<div>
<h2 class="mero-dialog-title" id="confirm-environment-title">Delete environment?</h2>
<p class="mero-description" id="confirm-environment-description">Confirm deletion of the Acme production environment. This demo simulates the request.</p>
</div>
<form method="post" action="/demo/catalog/typed-confirmation?outcome=rejected" hx-post="/demo/catalog/typed-confirmation?outcome=rejected" hx-target="this" hx-swap="outerHTML"
class="mero-stack" data-mero-form data-mero-confirm data-mero-return-focus="#confirm-environment-opener">
<div class="mero-field">
<label class="mero-label" for="confirm-environment-input">Confirmation phrase</label>
<code class="mero-confirm-phrase" id="confirm-environment-phrase" data-mero-confirm-phrase>acme/production/delete</code>
<input class="mero-input" id="confirm-environment-input" name="phrase" autocomplete="off" spellcheck="false"
aria-describedby="confirm-environment-phrase confirm-environment-hint" data-mero-confirm-input required
value="" autofocus>
</div>
<div class="mero-field">
<label class="mero-label" for="confirm-environment-reason">Reason</label>
<textarea class="mero-textarea" id="confirm-environment-reason" name="reason" rows="2" data-mero-confirm-reason required></textarea>
</div>
<p class="mero-description" id="confirm-environment-hint" data-mero-confirm-hint role="status">Type the phrase exactly to enable confirmation.</p>
<p class="mero-field-error" data-mero-form-error role="alert" hidden></p>
<div class="mero-dialog-footer">
<button class="mero-button mero-button-secondary" type="button" data-mero-close>Cancel</button>
<button class="mero-button mero-button-danger" type="submit" data-mero-confirm-submit aria-describedby="confirm-environment-hint" disabled>Delete environment</button>
</div>
</form>
</div>
</dialog>
</div>HTTP exchange
Use the preview to see the request and the HTML your server returns.Typed confirmation is a UX guard only. The server must re-check the phrase and permissions before acting. This demo also requires a reason of at least 8 characters on the server. To make the reason optional, remove required from that field and update the server validation. This endpoint returns HTTP 403 after validation.
Use in your app
Copy these tags into your page head once. Serve the files at the paths shown, then add the example’s template to your page.
Page assets
<link rel="stylesheet" href="/mero.css">
<script defer src="/vendor/htmx.min.js"></script>
<script defer src="/mero.js"></script>
<script defer src="/mero-forms.js"></script>Point the HTMX attributes at your own HTML endpoints. Use the live preview’s HTTP exchange to inspect the request and response.
Download library and examples ↓