Skip to content

Instantly share code, notes, and snippets.

@trey
Last active February 27, 2024 01:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trey/d04adbcc234800e90ff2ea3db3adcb46 to your computer and use it in GitHub Desktop.
Save trey/d04adbcc234800e90ff2ea3db3adcb46 to your computer and use it in GitHub Desktop.
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