jpkleemans / angular-validate

Painless form validation for AngularJS. Powered by the jQuery Validation Plugin.
MIT License
68 stars 33 forks source link

addClassRules #14

Closed stamminator closed 7 years ago

stamminator commented 7 years ago

I've used the addClassRules function in jQuery Validate very often. It's handy when I need the same validation on multiple fields that have different names but the same class. I have not been able to get this working using your angular implementation.

I tried modifying the angular .provider function in angular-validate.js like this, but it didn't work.

.provider('$validator', function () {
    $.validator.setDefaults({
        onsubmit: false // to prevent validating twice
    });

    return {
        setDefaults: $.validator.setDefaults,
        addMethod: $.validator.addMethod,
        addClassRules: $.validator.addClassRules, // I added this line
        setDefaultMessages: function (messages) {
            angular.extend($.validator.messages, messages);
        },
        format: $.validator.format,
        $get: function () {
            return {};
        }
    };
});

Do you know how I can get this working? Thanks.