当我尝试使用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
答案 0 :(得分:2)
我误解了取决于规则方法。您需要将其值应用于规则方法。所以,例如
$('#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>
该领域&#39;学校&#39;需要取决于字段&#39; school_id&#39;有一个长度。