I\'ve worked on a fiddle to show the simple validation that I\'m trying to do for my user ID field:
I encountered the same problem, and use this way works, not use the remote method:
$.validator.addMethod("userIdCheck", function(value, element, params) {
if (event.type == "blur" || event.type == "focusout") {
var result;
$.ajax({url: "path", async: false,
success: function(data){
result = data;
}})
return result;
} else {
return true;
}
}, "The user ID is already in use");
But this don't work on firefox, event undefined. So I modefied the source code(anyone has another way?):
function delegate( event ) {
var validator = $.data( this[ 0 ].form, "validator" ),
eventType = "on" + event.type.replace( /^validate/, "" ),
settings = validator.settings;
// add event to validator
validator.event = event;
if ( settings[ eventType ] && !this.is( settings.ignore ) ) {
settings[ eventType ].call( validator, this[ 0 ], event );
}
}
then we can use in this way:
$.validator.addMethod("userIdCheck", function(value, element, params) {
var eventType = this.event.type;
if (eventType == "blur" || eventType == "focusout") {
var result;
$.ajax({url: "path", async: false,
success: function(data){
result = data;
}})
return result;
} else {
return true;
}
}, "The user ID is already in use");
Not prefect enough, but this is the only way I find to solve this problem.