简体   繁体   English

jQuery验证规则取决于生成未捕获的TypeError

[英]Jquery Validation Rule Depends Generates Uncaught TypeError

When I try to use jQuery validation rules depends as follows: 当我尝试使用jQuery验证规则时,取决于以下内容:

<script>
$('#sign-up-form form').validate({
    rules: {
        state: "required",
        school: {
            depends: function(element) {
                return $("#id_school_id").val().length;
                }
            }
    }
});
</script>

Each time the depends part of the rule runs I get Uncaught TypeError: Cannot read property 'call' of undefined 每次规则的依赖部分运行时,我都会得到Uncaught TypeError: Cannot read property 'call' of undefined

The id that I'm checking is there (#id_school_id). 我要检查的ID在那儿(#id_school_id)。 I'm using jquery.validation.js v 1.11.1 我正在使用jquery.validation.js v 1.11.1

I misunderstood depends to be a rule method. 我误会了,要说是规则方法。 You need to apply its value to a rule method. 您需要将其值应用于规则方法。 So, for example 因此,例如

$('#sign-up-form form').validate({
rules: {
    state: "required",
    school: {
        required: {
            depends: function(element) {
                return $("#id_school_id").val().length;
            }
        }
    }
},
messages: {
    school: "Please choose a valid school name from the choices presented"
}
});

</script>

Whether the field 'school' is required depends on the field 'school_id' having a length. 是否需要字段“学校”取决于字段“ school_id”的长度。

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

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