Reputation: 419
I would like to create a form that validates each field if the user looses focus on a field.
So for example, a user may focus on the username field, not fill anything in and then tab out.
I've come across this jQuery plugin http://jqueryvalidation.org/
However it only seems to work when a user clicks the submit button.
Has anyone manipulated it so that it will do it will validate the form before the submit button is pressed?
Many Thanks
Upvotes: 0
Views: 1917
Reputation: 6820
There might be a better way to do this, but you can use the .valid()
function on blur to trigger validation on your inputs when the user exits the field.
$('input').on('blur', function() {
$(this).valid();
});
Note: You will need to call .validate()
on your form before you can use the valid()
function, which you should be doing already if it works on submit.
Upvotes: 1