Quote OP:
"Instead of adding a
label
withclass="error"
, I would like to add.error
to thelabel
I already have ... I just want the<label>
to gain the class.error
on a bad validation."
Use the following callback functions to over-ride the defaults...
$('#myform').validate({
// your other options, rules, etc,
errorPlacement: function() {
return false; // suppress the default error messages
},
highlight: function (element) {
// on error add the error class to your label
$(element).prev('label').addClass('error');
},
unhighlight: function (element) {
// on validation remove the error class from your label
$(element).prev('label').removeClass('error');
}
});
"And of course, I want it to have eg, .error .invalid for emails."
Quote OP Comment:
"I meant that I would like my label to have class="error invalid" when the user inputs a bad email address (for email inputs only, obviously). And simply 'error', when required but missing. I'm currently only checking my elements for 'required' and 'email' (as applicable)."
This is impossible. The plugin simply evaluates the rules and spits out the appropriate error message along with an error class
or a valid class
when there is no error. There is no way to specify a different error class
for each rule.