jQuery验证无法调用未定义的方法“调用"
这个错误使我发疯,一切似乎都井然有序,但是希望我缺少一些简单的东西.
This errors driving me nuts, everything seems to be in order, but hopefully I'm missing something simple.
我的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."
);
基本上,问题不在自定义验证范围内,但无论如何我还是把它们扔在了这里……提交时表单可以很好地验证,但是尝试时有一些门牌号"和街道"会引发此错误填充它们.
Basically the issue is outside of the custom validations, but I threw them up here anyways...the form is validating fine when submitting, but there are a few 'house number' and 'street' that throw this error when trying to fill them in.
例如,我提交的表格中的街道编号为空,则验证有效,但是当我填写输入内容时,模糊时会抛出此错误.
For example, I submit the form with an empty street number, the validation works, but when I fill in the input, on blur this error is being thrown.
错误出现在jquery.validate中的var rule = { method: method, parameters: rules[method] }
行:
The error is in jquery.validate here on the var rule = { method: method, parameters: rules[method] }
line:
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
maxLength is not camel cased, and should be maxlength
尽管equalTo是骆驼套...似乎不一致,但很高兴我发现了
Although equalTo is camel cased...seems inconsistant, but glad I figured it out