imacrayon / alpine-ajax

An Alpine.js plugin for building server-powered frontends.
https://alpine-ajax.js.org
MIT License
558 stars 11 forks source link

Allow disabling ajax per submit #42

Closed bgilhome-now closed 8 months ago

bgilhome-now commented 9 months ago

I needed a feature to skip ajax and submit normally per submit element - in my case, Shopify's cart form submission's response contains {redirect: false} when using ajax (or native fetch), but still somehow redirects when submitting without ajax (e.g. maybe via some logic on cart page bootstrap).

I've added the ability to set x-ajax.disable on a submit element (in my case the cart form 'Checkout' submit button) to submit the form without ajax. NB x-ajax isn't a real directive. Could be used to set other config per submit element?

imacrayon commented 8 months ago

Hi Bryce,

Thanks for the PR and sorry for the radio silence on this. I've been bikeshedding on the name of this attribute over my winter break. I'll try to get this merged Friday.

bgilhome-now commented 8 months ago

Thanks @imacrayon ! Yes names are hard :) I wasn't really sure myself what to call it that makes the most sense.

imacrayon commented 8 months ago

I'm planning a feature similar to HTMX's boost that I would like to reserve for the x-ajax directive. To avoid conflict I'm going to rename this attribute formnoajax, I know that's a weird name, but it's aligns nicely with HTML's formnovalidate.