2013-02-15 3 views
12

Ho questo codice modulo validatore ho ereditato, che sto ottenendo questo errore:

$.validator.methods[method] is undefined 

e sotto che sta mostrando

'maxlength:$.validator.format("Please enter no more than {0} characters.")' 

I ho letto che potrebbe essere l'errore di ortografia o il metodo che viene chiamato che non c'è. Ma non riesco a vederlo .. anche leggere sull'elemento dei dati remoti potrebbe causare problemi, ma l'ha rimosso.

edit: Ho caricato compressa nessuno js punti di codice e di errore a questa linea

var result = $.validator.methods[method].call(this, element.value.replace(/\r/g, ""), element, rule.parameters); 

codice:

$(document).ready(function(){ 
    $("#regForm").validate({ 
     rules:{ 
      confirmemailaddress: { 
       equalTo: "#emailaddress" 
      }, 
      password: { 
       password: "#username" 
      },    
      adminpassword: { 
       adminpassword: "#adminusrname" 
      },    
      retypepassword: { 
       equalTo: "#password" 
      }, 
      retypenewpassword: { 
       equalTo: "#newpassword" 
      }, 
      retypeadminpassword: { 
       equalTo: "#adminpassword" 
      }, 
      interest2: { 
       notEqualTo: "#interest" 
      }, 
      retypenewadminpassword: { 
       equalTo: "#newadminpassword" 
      }, 
      emailaddress: {    
       remote: { 
        url: $("#validationUrl").val(), 
        type: "post", 
        data: { 
          emailaddress: function() { 
          return $("#emailaddress").val(); 
          }, 
          registrationtype: function() { 
          return $("#registrationtype").val(); 
          }, 
          userctx: function() { 
          return $("#userctx").val(); 
          },                       
          identityid: function() { 
          return $("#identityid").val(); 
          }                       
        } 
       } 
      }, 
      username: {     
       remote: { 
        url: $("#validationUrl").val(), 
        type: "post", 
        data: { 
          username: function() { 
          return $("#username").val(); 
          },        
          registrationtype: function() { 
          return $("#registrationtype").val(); 
          }, 
          userctx: function() { 
          return $("#userctx").val(); 
          }                
        } 
       } 
      }, 
      adminusrname: { 
       notEqualTo: "#username",     
       remote: { 
        url: $("#validationUrl").val(), 
        type: "post", 
        data: { 
          username: function() { 
          return $("#adminusrname").val(); 
          },        
          registrationtype: function() { 
          return $("#registrationtype").val(); 
          }, 
          userctx: function() { 
          return $("#userctx").val(); 
          }                
        } 
       }     
      }, 
      oldauthusername: {     
       remote: { 
        url: $("#validationUrl").val(), 
        type: "post", 
        data: { 
          username: function() { 
          return $("#oldauthusername").val(); 
          },        
          registrationtype: function() { 
          return $("#registrationtype").val(); 
          }, 
          userctx: function() { 
          return $("#userctx").val(); 
          }                
        } 
       } 
      } 
     }, 
     messages: { 
      instname:{   
       required: "Please specify the name of your institution" 
       }, 
       firstname:{ 
       required: "Please specify your First Name", 
       minlength: jQuery.format("At least {0} characters required!") 
       }, 
      lastname:{ 
       required: "Please specify your Name", 
       minlength: jQuery.format("At least {0} characters required!") 
      },   
      interest:{ 
       required: "Please choose an interest area" 
      },   
      interest2:{ 
       required: "Please choose a second interest area", 
       notEqualTo: "Please choose a different interest area to the above" 
      },   
      emailaddress:{ 
       required: "We need your Email Address to contact you", 
       email: "Your Email Address must be in the format [email protected]", 
       remote: jQuery.format("{0} is already in use") 
      }, 
      confirmemailaddress:{ 
       required: "Please confirm your Email Address", 
       email: "Your Email Address must be in the format [email protected]", 
       equalTo: "Please enter the same Email Address as above" 
      }, 
      username: { 
       required: "Please specify your User Name", 
       minlength: jQuery.format("At least {0} characters required!"), 
       remote: jQuery.format("{0} is already in use") 
      }, 
      oldauthusername: { 
       required: "Please specify your User Name", 
       minlength: jQuery.format("At least {0} characters required!"), 
       remote: jQuery.format("{0} is already in use") 
      }, 
      password: { 
       required: "Please specify your Password", 
       minlength: jQuery.format("At least {0} characters required!") 
      }, 
      retypepassword: { 
       required: "Please retype your Password", 
       minlength: jQuery.format("At least {0} characters required!"), 
       equalTo: "Enter the same password as above" 
      }, 
      adminusrname: { 
       required: "Please specify your User Name", 
       minlength: jQuery.format("At least {0} characters required!"), 
       remote: jQuery.format("{0} is already in use"), 
       notEqualTo: "Your username must be different to the institution username" 
      }, 
      adminpassword: { 
       required: "Please specify your Password", 
       minlength: jQuery.format("At least {0} characters required!") 
      }, 
      retypeadminpassword: { 
       required: "Please retype your Password", 
       minlength: jQuery.format("At least {0} characters required!"), 
       equalTo: "Enter the same Password as above" 
      },    
      retypenewpassword: { 
       required: "Please retype your New Password", 
       minlength: jQuery.format("At least {0} characters required!"), 
       equalTo: "Enter the same password as above" 
      }, 
      termsandconditions: { 
       required: "Please tick the checkbox to confirm that you have read and agree to the terms and conditions before proceeding." 
      } 
     } 
    }); 

    $("#ipmarker .asterix").hide();      
    $("#logincredmarker .asterix").hide();  

    $("#validateContact").click(function() { 
     var errors = false; 
     var firstError; 
     $(".contact .required").each(function() { 
      if(!$("#regForm").validate().element(this)) 
      { 
       if (! errors) 
        firstError = $(this); 
       errors = true;   
      } 
     }); 
     $(".contact .email").each(function() { 
      if(!$("#regForm").validate().element(this)) 
      { 
       if (! errors) 
        firstError = $(this); 
       errors = true;   
      } 
     }); 
     if(errors) 
     { 
      firstError.focus(); 
      return false; 
     } 
     else 
     { 
      $(".contact").hide(); 
      $(".authentication").show(); 
      if($('#usrname').is(':checked')) 
       $("#usrname").parent("legend").parent("fieldset").find(".regInput").find(".optRequired").addClass("required"); 
      $(".regStep2").removeClass("linkDisabled"); 
      scroll(0,0); 
      return false; 
     } 
    }); 

    var validateAuthenticationStep = function(){ 
        if (( $("#oldauthhiddenusername").val() != null && $("#oldauthhiddenusername").val() != '') 
         || ( $("#oldauthusername").val()  != null && $("#oldauthusername").val()  != '') 
         || ( $("#iprange").val()    != null && $("#iprange").val()    != '') 
         || ( $("#username").val()    != null && $("#username").val()    != '') 
         || ( $("#externalid").val()    != null && $("#externalid").val()   != '') 
         ) 
     {   
      var errors = false; 
      $(".authentication .required, .authentication .checkIP, .authentication .email").each(function() { 
       if(!$("#regForm").validate().element(this)) 
       { 
        if (! errors) 
         firstError = $(this); 
        errors = true;   
       } 
      }); 
      if(errors) 
      { 
       firstError.focus(); 
       return false; 
      } 
      else 
       return true; 
     } 
     else 
     { 
      $(".authenticationselectionerror").show(); 
      scroll(0,0);     
     } 
    } 

    $("#validateAuthentication").click(function() { 
     if($("#username").val()!="") { 
      $("#password").addClass("required"); 
      $("#retypepassword").addClass("required"); 
     } 
     else 
     { 
      $("#password").removeClass("required"); 
      $("#retypepassword").removeClass("required"); 
     } 

     if (validateAuthenticationStep()) 
     { 
      $(".authentication").hide(); 
      $(".authenticationAdmin").show(); 
      $(".regStep3").removeClass("linkDisabled"); 
     }   
     return false; 
    }); 

    $("#validateUpdateAuthentication").click(function() { 
     if(validateAuthenticationStep()) 
      $("#regForm").submit(); 
     return false; 
    });  





}); 
+0

'maxlength:. $ Validator.format ("Si prega di inserire non più di {0} caratteri.")' Dove posso trovare questo? ho controllato il tuo codice e non riesco a vederlo. Hai usato firebug per vedere quale validazione fallisce davvero? – gulty

+0

controlla #nomeutente e #usrname <- dovrebbe essere così? (Non riesco a vedere l'html quindi non so cosa hai specificato dove) – gulty

+0

sembrava cercare il 'Metodo' 'notEqualto' così lo aggiunse .... e lo aggiustò jQuery.validator.addMethod ('notEqualTo', function (value, element, param) {return value! = jQuery (param) .val();}, 'Non deve essere uguale a {0}.'); – Mark

risposta

24

State ottenendo questo errore perché si sta chiamando un non- esistente rule ...

rules: { 
    //other rules, 
    interest2: { 
     notEqualTo: "#interest" 
    }, 
} 

notEqualTo non è una regola valida inclusa in questo plug-in. È necessario rimuoverlo o creare una nuova regola denominata notEqualTo utilizzando lo plugin's built-in addMethod() method. Qualcosa di simile ...

jQuery.validator.addMethod('notEqualTo', function(value, element, param) { 
    return value != jQuery(param).val(); 
}, 'Must not be equal to {0}.'); 
+0

dl_name: {ranglelength: [3,100]}, ho fatto anche lo stesso errore, mi ci è voluto un bianco per notare l'errore di battitura. –