2012-10-17 16 views
8

Questi errori mi fanno impazzire, tutto sembra essere in ordine, ma spero che manchi qualcosa di semplice.jQuery Validate Impossibile chiamare il metodo 'call' di undefined

codice nel mio 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 
       } 
      } 
     }); 

convalide personalizzati

$.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." 
); 

In sostanza il problema è al di fuori delle convalide personalizzati, ma li ho vomitato qui comunque ... la forma sta convalidando bene quando invio, ma ci sono alcuni "numeri civici" e "strada" che generano questo errore quando si tenta di riempirli.

Per esempio, invio il modulo con una strada vuota n umber, la validazione funziona, ma quando inserisco l'input, su blur questo errore viene lanciato.

L'errore è in jquery.validate qui sulla linea 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; 
       } 
      } 

Grazie in anticipo per tutti i puntatori

+0

Per sting è meglio usare indexOf invece di === –

+0

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

+0

Cambia anche i selettori rimuovendo i titolari di ContentPlace ... Qualcosa di simile invece di 'ctl00 $ SecondaryPlaceHolder $ txPayloadDate' fai questo '[id * = txPayloadDate]' –

risposta

12

errore di battitura Dumb da parte mia era il colpevole

maxLength non è cammello cased, e dovrebbe essere maxlength

Anche se uguale è cammello in cammello ... sembra incoerente, ma contento di averlo capito

+7

Yuk! L'autore del plug-in dovrebbe essere rammollito cerimonialmente. –

Problemi correlati