I know Google\'s Geocoder service is asynchronous, but I need a way to return true or false to my custom jQuery Validate method after the google geocoder results have returned a
As I mentioned in my comment, pull the default onkeyup
function from the plugin and modify it for your over-ride.
$("#contact").validate({
onkeyup: function(element, event) {
if (element.name == "zip-code") {
return; // no onkeyup validation at all
} else {
// default onkeyup validation in here
var excludedKeys = [
16, 17, 18, 20, 35, 36, 37,
38, 39, 40, 45, 144, 225
];
if ( event.which === 9 && this.elementValue( element ) === "" || $.inArray( event.keyCode, excludedKeys ) !== -1 ) {
return;
} else if ( element.name in this.submitted || element.name in this.invalid ) {
this.element( element );
}
}
},
....
In the proof-of-concept DEMO below, hit the submit
button to first get past the "lazy" validation, then compare the behavior of the two fields. The first field is validating for an email address on every keyup
event. The second field is not validating for email on keyup
events at all, only on focusout
and submit
.
DEMO: http://jsfiddle.net/vbcpyv3q/