jQuery Validate 无法调用未定义的方法 'call'

标签 jquery asp.net jquery-validate

这个错误让我发疯,一切似乎都按顺序进行,但希望我错过了一些简单的东西。

我的aspx中的代码

        $('#myForm').validate({
            rules: {
                'ctl00$SecondaryPlaceHolder$txPayloadDate': {
                    required: true,
                    date: true
                },
                'ctl00$SecondaryPlaceHolder$ddlMapPlat': {
                    required: true
                },
                'ctl00$SecondaryPlaceHolder$txtBlock': {
                    maxLength: 3
                },
                'ctl00$SecondaryPlaceHolder$txtLeakNumber': {
                    number: true,
                    maxLength: 27
                },
                'ctl00$SecondaryPlaceHolder$txtHouseNumber': {
                    required: true,
                    maxLength: 10,
                },
                'ctl00$SecondaryPlaceHolder$txtStreet': {
                    required: true,
                    maxLength: 100
                },
                'ctl00$SecondaryPlaceHolder$txtCity': {
                    required: true,
                    maxLength: 50
                },
                'ctl00$SecondaryPlaceHolder$txtReading': {
                    isPositiveInteger: true,
                    maxLength: 100
                },
                'ctl00$SecondaryPlaceHolder$ddlInfoCodes': {
                    existsWithLowReading: true
                },
                'ctl00$SecondaryPlaceHolder$txtLocationRemarks': {
                    maxLength: 500
                },
                'txtGrade2RequestedRepairDate': {
                    date: true
                },
                'ctl00$SecondaryPlaceHolder$ddlEquipment': {
                    required: true
                }
            }
        });

自定义验证

$.validator.addMethod("isPositiveInteger",
    function (value, element) {
        if($.trim(value) !== '')
            return /^\d+$/.test(value);
        return true;
    },
    "Must be a valid integer."
);


$.validator.addMethod("existsWithLowReading",
    function (value, element) {
        if (parseFloat($('#SecondaryPlaceHolder_txtReading').val() <= 2) && value.length < 1) {
            return false;
        }
        return true;
    },
    "Info Code required if Reading % is less than three."
);

基本上,问题不在自定义验证范围内,但我还是把它们扔在这里...提交时表单验证正常,但有一些“门牌号”和“街道”在尝试时抛出此错误填写它们。

例如,我提交带有空街道号码的表单,验证有效,但是当我填写输入时,在模糊时会抛出此错误。

错误出现在 jquery.validate 的 varrule = { method: method,parameters:rules[method] } 行:

 check: function (element) {
            element = this.validationTargetFor(this.clean(element));

            var rules = $(element).rules();
            var dependencyMismatch = false;
            var val = this.elementValue(element);
            var result;

            for (var method in rules) {
                var rule = { method: method, parameters: rules[method] };
                try {

                    result = $.validator.methods[method].call(this, val, element, rule.parameters);

                    // if a method indicates that the field is optional and therefore valid,
                    // don't mark it as valid when there are no other rules
                    if (result === "dependency-mismatch") {
                        dependencyMismatch = true;
                        continue;
                    }
                    dependencyMismatch = false;

                    if (result === "pending") {
                        this.toHide = this.toHide.not(this.errorsFor(element));
                        return;
                    }

                    if (!result) {
                        this.formatAndAdd(element, rule);
                        return false;
                    }
                } catch (e) {
                    if (this.settings.debug && window.console) {
                        console.log("exception occured when checking element " + element.id + ", check the '" + rule.method + "' method", e);
                    }
                    throw e;
                }
            }

提前感谢您的指点

最佳答案

罪魁祸首是我的愚蠢打字错误

maxLength 不是驼峰式大小写,应该是 maxlength

虽然 equalTo 是驼峰式大小写...似乎不一致,但很高兴我明白了

关于jQuery Validate 无法调用未定义的方法 'call',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12944068/

相关文章:

javascript - css 上的子菜单悬停菜单问题

jquery - 使用 jquery 插件时日期选择器验证不起作用

PHP 或 jQuery/PHP 分页

asp.net - 智能卡身份验证 ASP.NET

c# - 如何访问共享主机空间上的文件夹?

javascript - 坚持尝试在 IE 中模仿 JavaScript 动态属性

javascript - JQuery 验证插件最大长度?

javascript - bxSlider:如何防止bxSlider转到下一张幻灯片?

javascript - jQuery 中最近的祖先节点

c# - 在 <%=%> 中找不到变量