I have this form in my app and I will submit it via AJAX, but I want to use HTML5 for client-side validation. So I want to be able to force the form validation, perhaps via jQuery.
I want to trigger the validation without submitting the form. Is it possible?
You speak of two different things "HTML5 validation" and validation of HTML form using javascript/jquery.
HTML5 "has" built-in options for validating a form. Such as using "required" attribute on a field, which could (based on browser implementation) fail form submission without using javascript/jquery.
With javascrip/jquery you can do something like this
I know this has already been answered, but I have another possible solution.
If using jquery, you can do this.
First create a couple of extensions on jquery so you can resuse these as needed.
Next do something like this where you want to use it.
I had a rather complex situation, where I needed multiple submit buttons to process different things. For example, Save and Delete.
The basis was that it was also unobtrusive, so I couldn't just make it a normal button. But also wanted to utilize html5 validation.
As well the submit event was overridden in case the user pressed enter to trigger the expected default submission; in this example save.
Here is the efforts of the processing of the form to still work with/without javascript and with html5 validation, with both submit and click events.
xHTML
JavaScript
The caveat to using Javascript is that the browser's default onclick must propagate to the submit event MUST occur in order to display the error messages without supporting each browser in your code. Otherwise if the click event is overridden with event.preventDefault() or return false it will never propagate to the browser's submit event.
The thing to point out is that in some browsers will not trigger the form submit when the user presses enter, instead it will trigger the first submit button in the form. Hence there is a console.log('form submit') to show that it does not trigger.
To check all the required fields of form without using submit button you can use below function.
You have to assign required attribute to the controls.