0

This is my method:

$.validator.addMethod("password_verify_old", function(value, element){ 


     $.ajax({
         type: "GET", 
         url: verify_old_password_url,
         data: {oldPassword: value},   
         dataType: "json",
         success: function (msg) { 
           return eval(msg);
         }
       });



}, "Old password is incorrect."); 

Here, I'm calling my controller which returns just a "true" String. Why does the jquery.validate.js interpret this as 'false'?

mpmp
  • 2,409
  • 4
  • 33
  • 46
  • 1
    maybe because ajax is asynchronous, so your validate function has already finished when the response arrives... – Tallmaris Nov 09 '12 at 12:53

1 Answers1

1

I dont believe you can add a validation method using addMethod that calls ajax

What you are looking for is remote option in the rules, which will make an ajax call to a url specified for the value in the input

   $(form).validate({
       rules:{ your_field :{
               required:true,
               remote: check_passwordurl,

Oh yea have your check password url return a boolean true or false, else you would need todo some extra coding as this SO shows How to use jQuery to remotely validate a field that depends on another field in the form?

Community
  • 1
  • 1
Jay Rizzi
  • 4,196
  • 5
  • 42
  • 71