Form ‘onsubmit’ not getting called

When you call the form’s submit function, the submit event is not fired. This is by design, the assumption is that if you’re triggering the submission from code, you’ve already done any necessary validation. (Note that this is true of the HTMLFormElement#submit function; it is not necessarily true of the wrappers libraries put around it.)

In your example, I would remove the click handler on the button. It’s a submit button, so just put any relevant logic in the submit event on the form. Alternately, if you prefer, call validate() as part of the button’s click.

Leave a Comment