Jquery 验证规则依赖生成未捕获的类型错误

Jquery Validation Rule Depends Generates Uncaught TypeError

当我尝试使用 jQuery 验证规则取决于如下:

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

每次运行规则的依赖部分时,我都会得到 Uncaught TypeError: Cannot read property 'call' of undefined

我正在检查的 ID 在那里 (#id_school_id)。 我正在使用 jquery.validation.js v 1.11.1

我误会了 depends 是一个规则方法。您需要将其值应用于规则方法。所以,例如

$('#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>

字段'school'是否必填取决于字段'school_id'的长度。