Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Validate Cannot call method 'call' of undefined

This errors driving me nuts, everything seems to be in order, but hopefully I'm missing something simple.

Code in my 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
                }
            }
        });

custom validations

$.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.

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;
                }
            }

Thanks in advance for any pointers

like image 978
mgaughan Avatar asked Oct 17 '12 21:10

mgaughan


1 Answers

Dumb typo on my part was the culprit

maxLength is not camel cased, and should be maxlength

Although equalTo is camel cased...seems inconsistant, but glad I figured it out

like image 194
mgaughan Avatar answered Oct 22 '22 13:10

mgaughan