jQuery Validation Plugin

xxVolcomxx

New Member
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:\[code\]$.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." );\[/code\]Unfortunately it seems like the plugin moves on regardless of the callback function. I found someone suggest doing something like the following:\[code\]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." );\[/code\]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?
 
Back
Top