2012-10-17 131 views
8

这个错误使我疯狂,一切似乎都是为了,但希望我错过了简单的东西。jQuery验证无法调用未定义的方法“调用”

代码在我的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." 
); 

基本上问题是自定义的验证之外,但是我把他们在这里反正...形式验证罚款时,提交,但有几个'房屋号码'和'街道',试图填补他们时,会抛出此错误。

例如,我提交表单与一个空的街道n棕褐色,验证工作,但是当我填写输入,在模糊这个错误被抛出。

的错误是在jquery.validate这里的var rule = { 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; 
       } 
      } 

预先感谢任何指针

+0

为了更好地使用indexOf而不是=== –

+0

if(result.indexOf(“dependency-mismatch”)> -1) –

+0

还要通过移除ContentPlace持有者来更改您的选择器...类似这样的事情而不是'ctl00 $ SecondaryPlaceHolder $ txPayloadDate'做这个'[id * = txPayloadDate]' –

回答

12

在我的部分错字阿呆是罪魁祸首

最大长度不驼应该是最大长度

虽然equalTo是骆驼套...似乎不一致,但很高兴我想通了

+7

唷!插件作者应该被仪式地解除锁定。 –

相关问题