1

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()?

1 Answer 1

1

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.

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

4 Comments

How can I set the errors per element if I am using css classes as opposed to id?
@devlife - check out the metadata/validation demo here: jquery.bassistance.de/validate/demo/… it can be used with data attributes as well.
I must be missing something. Here is the html for my input: <input class="field datePicker arrivalDate requiredDatePicker departureDate {required:true, date:true, messages:{required:'enter a valid date', date:'enter a valid date'}}"type="text" value="">. However, it is not being validated...
apparently that's what I was missing =)

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.