Manually fail a form submit

I have a form that submits a js query. If there is an error or a validity check fails in the js, how to do I prevent the form from thinking it has submitted successfully and doing things like resetting after submit?

Related, I can have multiple submit handlers (one for form submission, one to close model and so on.) Do all of these run in parallel or do they bubble? Is there a knowable order in which they execute? If I can fail one, can I prevent bubbling up to the rest?

It will help if you post your process so I can see what you are trying to achieve. If you can, of course.

My process is:

  1. Call a js query on submit.
  2. js determines where the form is to be submitted and how based on the form contents.
  3. If there is an error in the js or my js determines entries are incorrect, the js finishes but the form component keeps acting as if the form was successfully submitted by running the remaining submitted events and clearing the form.

I am looking for something that duplicates the html submit cancel capability like:

<form onsubmit="return isValidForm()" />

If isValidForm() returns true the form is submitted to the server. If it returns false, all processing stops.

I am guessing this should be moved over to feature requests.

Hey @bradlymathews,

Would you be able to separate the JS query from the form submission and have it run as a prior action that then triggers the form submission only in some cases?

Rather than run your JS query 'On submit' you could change the Submit button to trigger your JS query (and not the Submit event) and then trigger the submit in your JS code using form1.submit().

Could that work for your use case?

Yeah, That would probably work perfectly. In fact I might just make that the standard pattern for all form submits from now on. You never know what might happen and having a way to roll back a submit is quite often very important.

It would still be nice to have a built way to handle this so I am moving this thread to feature requests.