微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

jquery – validator $.validator.methods [method]未定义

我有我已经继承的验证器表单代码,我收到这个错误
$.validator.methods[method] is undefined

并在此显示

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

我已经看到这可能是拼写错误或被称为不是的方法.但是看不到它..甚至阅读关于远程数据元素可能会导致问题,但把它打破了它.

编辑:我已经上传了没有压缩的js代码错误点到这一行

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

码:

$(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(),data: {
                          username: function() {
                            return $("#username").val();
                          },registrationtype: function() {
                             return $("#registrationtype").val();
                          },userctx: function() {
                             return $("#userctx").val();
                          }                                                            
                     }
                }
            },adminusrname: { 
                notEqualTo: "#username",remote: {
                    url: $("#validationUrl").val(),data: {
                          username: function() {
                            return $("#adminusrname").val();
                          },userctx: function() {
                           return $("#userctx").val();
                          }                                                            
                    }
                }                   
            },oldauthusername: {                
                remote: {
                    url: $("#validationUrl").val(),data: {
                          username: function() {
                            return $("#oldauthusername").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 name@domain.com",remote: jQuery.format("{0} is already in use") 
            },confirmemailaddress:{
                 required: "Please confirm your Email Address",equalTo: "Please enter the same Email Address as above" 
            },username: {
                required: "Please specify your User Name",minlength: jQuery.format("At least {0} characters required!"),oldauthusername: {
                required: "Please specify your User Name",password: {
                required: "Please specify your Password",minlength: jQuery.format("At least {0} characters required!")
            },retypepassword: {
                required: "Please retype your Password",equalTo: "Enter the same password as above" 
            },adminusrname: {
                required: "Please specify your User Name",remote: jQuery.format("{0} is already in use"),notEqualTo: "Your username must be different to the institution username" 
            },adminpassword: {
                required: "Please specify your Password",retypeadminpassword: {
                required: "Please retype your Password",equalTo: "Enter the same Password as above" 
            },retypenewpassword: {
                required: "Please retype your New Password",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;
    });     





});

解决方法

您收到此错误是因为您呼叫不存在的规则…
rules: {
    //other rules,interest2: {
        notEqualTo: "#interest"
    },}

notEqualTo不是此插件中包含的有效规则.您必须使用plugin’s built-in addMethod() method删除它或创建一个名为notEqualTo的新规则.这样的事情…

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

原文地址:https://www.jb51.cc/jquery/176425.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐