Using jQuery validation – validating on blur:
$('input, select, radio, checkbox').blur(function(){
$("#createAccount").validate().element(this);
});
If a user is tabbing through the form, and the field is optional, the field is validated as ok (and a class is added, changing the color etc. of the input field)
What I would like to do is to ignore validation for an empty field not required.
My current ignore is only for :hidden
ignore: ":hidden",
and when I tried:
ignore: ":hidden, .ignore",
this would throw an error on when any field was focused that had the class ignore. So that almost works, except if you ignore the field then the other validations on that field don’t trigger. So the field is optional, but there are still validations on it. I just don’t want it to trigger the success validation on an empty optional field.
thanks!
Edit
So the logic should be: onblur if empty and not required then ignore – if not empty then run the validations attached to that field.
This is what I did to accomplish this:
For an input that needed to be ignored until it had a value I added a class to the input – “ignore”
In the function, if an input has the class ignore and no value has been entered, then I remove the valid class I set in the validate call. When a value is entered, the normal validations will trigger on those items.