0

I use jquery.validate.js to validate the forms on our site. Today I updated the version of the validation plugin to v 1.9 and since then I have a problem with password validations on site.

I found why that is happen and now I looking for "correct" way to solve it. In previous version the method attributeRules was as follows:

attributeRules: function (element) {
            var rules = {};
            var $element = $(element);

            for (var method in $.validator.methods) {
                var value = $element.attr(method);                      
                if (value) {
                    rules[method] = value;
                }
            }    

            // maxlength may be returned as -1, 2147483647 (IE) and 524288 (safari) for text inputs
            if (rules.maxlength && /-1|2147483647|524288/.test(rules.maxlength)) {
                delete rules.maxlength;
            }

            return rules;
        }

In version 1.9, it looks a little bit differ:

attributeRules: function (element) {
            var rules = {};
            var $element = $(element);

            for (var method in $.validator.methods) {
                var value;

                // If .prop exists (jQuery >= 1.6), use it to get true/false for required
                if (method === 'required' && typeof $.fn.prop === 'function') {
                    value = $element.prop(method);
                } else {
                    value = $element.attr(method);
                }

                if (value) {
                    rules[method] = value;
                } else if ($element[0].getAttribute("type") === method) {
                    rules[method] = true;
                }
            }


            // maxlength may be returned as -1, 2147483647 (IE) and 524288 (safari) for text inputs
            if (rules.maxlength && /-1|2147483647|524288/.test(rules.maxlength)) {
                delete rules.maxlength;
            }

            return rules;
        }

I understand from that, that in previous versions, the method didn't check the type attribute of input element and didn't add "password" validator. In ver 1.9 it checks if element has type "password" and adds validator.

The question:
How to tell to jQuery.validator to ignore inputs with "password" type?

Thanks

7
  • Describe your problem. What do you really need? Commented Sep 20, 2012 at 13:27
  • I want to leave the validation rule "password" but I don't want that plugin will automatically validate all inputs with type='password' Commented Sep 20, 2012 at 13:34
  • What plugin do you use? github.com/posabsolute/jQuery-Validation-Engine Commented Sep 20, 2012 at 13:37
  • I use jquery.validate.js from bassistance.de/jquery-plugins/jquery-plugin-validation Commented Sep 20, 2012 at 13:40
  • I didn't understand you. How do you want to validate input[type="password"] (cause you want to leave password rule), but not to validate those inputs? Why do you need rule password, when you don't want to validate them? Commented Sep 20, 2012 at 13:50

1 Answer 1

1

Check out the ignore option. You can provide any selector to it, so what might work for you is something like this:

$('form').validate({
    ignore:'input[type="password"]'
});

If that is too general, I suggest adding a class such as ignoreValidation to all the appropriate inputs, and then use '.ignoreValidation' in the ignore option.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.