I really was trying to avoid asking this question. I have seen quite a few posts on SO regarding this plugin but they still didn't quite get it for me. Right now I have a new account registration form and I'm trying to write a custom method for validating a unique username. I would like to think that the following should work:
$.validator.addMethod(
"uniqueUsername",
function(value, element) {
$.post(
"http://" + location.host + "/scripts/ajax/check_username.php",
{
username: value
},
function(response) {
if(response == 'true') {
return true;
} else {
return false;
}
}
);
},
"This username is already taken."
);
Unfortunately it seems like the plugin moves on regardless of the callback function. I found someone suggest doing something like the following:
var result = false;
$.validator.addMethod(
"uniqueUsername",
function(value, element) {
$.post(
"http://" + location.host + "/scripts/ajax/check_username.php",
{
username: value
},
function(response) {
if(response == 'true') {
result = true;
} else {
result = false;
}
}
);
return result;
},
"This username is already taken."
);
But it seems to have a delay since it stores the value, then on the next event will set whatever the value is. What do you guys recommend?