Cancelling form submit in Turbo

So I’m trying to catch the form from submission because it’s a checkout format and I want to do some magic with payment provider JavaScript before I submit something on my backend.

I figured that I can add an event listener this.formTarget.addEventListener("turbo:submit-start", listener). But in an ideal world, I want to have an option to cancel it.

Right now I end-up doing event.detail.formSubmission.stop() during submit-start, but I still think it’s not ideal way.

Does anyone figure out a way to do this?

1 Like

Thanks for posting this. I have the exact same need and your solution does work but it throws a nasty exception. Would like to know what the proper way stopping a form submission based on validation. I’m using a stimulus controller to validate the form.