简体   繁体   English

jquery验证器addMethod不工作

[英]jquery validator addMethod not working

After much effort I've been completely unable to get the addMethod to work. 经过很多努力,我完全无法使addMethod工作。

The code i have is as follows: 我的代码如下:

$("#submitform").validate(
        {
            rules: {
                org_name: "required",
                email_address: "required",
                phone: "required",
                abn: "required",
                description: "required",
                geocomplete: "required"
            },
            messages: {
                org_name: "Required",
                email_address: "Required",
                phone: "Required",
                abn: "Required",
                description: "Required",
                geocomplete: "Required"
            },              
            submitHandler: function(event, validator) {     


                // submitForm();

            },
            invalidHandler: function(event, validator) {
                //code..
            }
    });

the addMethod addMethod

    $.validator.addMethod("org_name", function(value) {
     // return this.optional(element) || value == params[0] + params[1];
     console.log("hi" + value);alert('hi');
     return false;
    }, "Invalid");

and the target element 和目标元素

<input id="org_name" name="org_name" type="text" class="input-xlarge ">

The addMethod function is not being called, there are no errors and i'm at a loss with this one?? addMethod函数没有被调用,没有错误,我不知道这个? On the other hand the "Required" validation is working fine on the form as expected, this is my first foray into this plugin. 另一方面,“必需”验证在表单上正常工作正常,这是我第一次涉足这个插件。

Use the rule like, 使用规则,如,

 org_name: "org_name",

Your code should be like, 你的代码应该像,

 $("#submitform").validate(
    {
        rules: {
            org_name: "org_name",// input element: method name
            email_address: "required",
            phone: "required",
            abn: "required",
            description: "required",
            geocomplete: "required"
        },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM