htmx icon indicating copy to clipboard operation
htmx copied to clipboard

hx-confirm doesn't work for plain form submits

Open devxzero opened this issue 1 year ago • 2 comments

When hx-confirm is used without hx-post or a similar attribute, then hx-confirm is ignored, even though it can be useful in regular non-htmx forms. Especially in pages that use hx-confirm to delete the entity where the page is about, you often don't want ajax requests, but just a simple plain non-ajax post.

For example:

<!DOCTYPE html>
<html>
<head>
    <script src="htmx.1.9.6.min.js"></script>
</head>
<body>
    <form method="get" action="/test.html">
        <!-- This first button shows the confirm dialog when pressed -->
        <input type="submit" hx-confirm="Sure?" value="button1" hx-get="" />

        <!-- This second button does not show the confirm dialog when pressed -->
        <input type="submit" hx-confirm="Sure?" value="button2" />
    </form>
</body>
</html>

Wouldn't it be better if hx-confirm also works if no other hx attributes are present?

Update: changed it to a better and more complete example.

devxzero avatar Sep 27 '23 22:09 devxzero

I agree, there is no reason hx-confirm should not work here. Seems logical that it should work.

svenberkvens avatar Nov 29 '23 19:11 svenberkvens