Skip to content

Instantly share code, notes, and snippets.

@trey
Last active Jan 20, 2023
Embed
What would you like to do?
JavaScript confirmation message with Alpine.js and htmx
<!--
https://alpinejs.dev/directives/on#prevent
https://github.com/alpinejs/alpine/issues/150#issuecomment-580452229
-->
<form x-data action="/something" @submit.prevent="if (confirm('Are you sure?')) $el.submit()" method="post">
<button aria-label="Delete this">[some icon]</button>
</form>
<!--
https://htmx.org/attributes/hx-confirm/
https://htmx.org/attributes/hx-delete/
-->
<form action="/something" hx-confirm="Are you sure?" method="post">
<button hx-delete="/something" aria-label="Delete this">[some icon]</button>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment