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 can do it without submitting the form.
For example, if the form submit button with id "search" is in the other form . You can call click event on that submit button and call ev.preventDefault after that. For my case I validate form B from Form A submission. Like this
To check whether a certain field is valid, use:
To check if the form is valid, use:
If you want to display the native error messages that some browsers have (such as Chrome), unfortunately the only way to do that is by submitting the form, like this:
Hope this helps. Keep in mind that HTML5 validation is not supported in all browsers.
This is a pretty straight forward way of having HTML5 perform validation for any form, while still having modern JS control over the form. The only caveat is the submit button must be inside the
<form>
.html
js
from: html5 form validation