I have a HTML5 web application with numerous user-entered fields, and I would like to do some client-side validation on those fields in javascript before sending them to the
I've created a little helper. Just add this line of code and then you can use any button anywhere.
$("body [data-submit-form]").on("click", function (event) {
$("#" + $(event.target).data('submit-form')).valid();
});
Explanation: The jquery code listens for all clicks on an element with the attribute 'data-submit-form', in the listener the data-attribute gets extracted and then i trigger the valid method on the matching form.
NOTE: if you want to submit the form if the form is valid use this code:
$("body [data-submit-form]").on("click", function (event) {
var form = $("#" + $(event.target).data('submit-form'));
if (form.valid()) {
form.submit();
}
});