devlife
devlife

Reputation: 16145

How to assign an error message when adding css class validation rule

I have added a css class validation rule for jquery validator as follows:

jQuery.validator.addClassRules({
        requiredDatepicker: {
            required: true,
            date: true
        }
    });

However, when doing this I get the default error messages. How can I assign custom error messages when using addClassRules()?

Upvotes: 1

Views: 3651

Answers (1)

Nick Craver
Nick Craver

Reputation: 630389

You can't do this generally with the rule set, since class rules are just combinations of basic rules (for example even required is really required: { required: true } underneath) and those have the error messages. To get custom errors you'll have to set them per-element, or use the meta-data plugin to put the rules on the element directly.

Upvotes: 1

Related Questions