With validation 1.8, I used a $.blur function on all the form’s input elements to trigger validation on that field when the user tabs out:
$('#myform :input').blur(function() {
$("#myform").validate().element( this );
});
Which worked great. However I just updated to 1.9 and now my fields are validating on keyup instead of blur.
I didn’t change anything with my setup, just switched to 1.9.
I see there have been a lot of changes, but I don’t see additional documentation.
Any help would be appreciated.
Clarification
prior, my elements would initially validate on blur, but if an element was in an error state, the element would actively validate on keyup, etc. if a user went back in to make a change. This is my desired behavior. That on initial entry, there is no active validation until on blur, but once a field is in an error state the field should actively validate on change, keyup, etc.
Now, the element is validating on keyup on initial entry
By default, for text input, jQuery Validate is triggered on “blur” (
onfocusout:), “keyup” (onkeyup:) and “submit” (onsubmit:) events.To have it only validate fields on “blur” and “submit”, simply set
onkeyup:option to false…All versions work the same…
Working Demo (v1.10): http://jsfiddle.net/M2MLL/
Working Demo (v1.9): http://jsfiddle.net/KSgLb/
Working Demo (v1.8): http://jsfiddle.net/k87Lp/
The default behavior for
onfocusoutis such that validation on the field will only start to occur after something has been left in the field (or after the initial submit event), otherwise simply leaving the field empty and clicking away to a new field does nothing.If you want validation to occur on “blur” every single time, no matter what, just modify the callback function for
onfocusout:like this…Working Demo (v1.9): http://jsfiddle.net/eRNTu/
Version 1.10 also working: http://jsfiddle.net/Mev8v/
BTW: Although I wouldn’t do this with
.blur(), your original code was working fine with v1.9 and v1.10. However, I believe that leveraging the internal functionality of the plugin’sonfocusout:option is a much more robust way to achieve your goal.EDIT 2:
In response to OP’s last clarification:
Here is a new working demo which modifies the default callback function for
onkeyup:The field will ignore any
onkeyupvalidation initially or when no error is being shown. Only when there is an active error and the user goes back to the field willonkeyupvalidation start to operate.Working Demo: http://jsfiddle.net/6s4rj/