0

I'm using jquery validate to validate 3 attributes (minlength, maxlength, required) in the element.

<input id="jumbotronSearch" type="text" class="form-control input-lg" placeholder="Location" required maxlength="50" minlength="4"/> 

But when the error message is displayed it displays it in black, not red.

From seeing other threads and sites that demo and display validation error messages it seems like the message should be in red and the border of the element will be red too!?? Do I have to style this myself or am I missing some file or a configuration parameter for jquery validate to ge tit to show in red?

Here is what the error message looks like, see the message is black, not red and the border of the element isn't red!

enter image description here

2
  • There are NO stylesheets included with this plugin. If it's red, it has nothing to do with jQuery Validate. Commented Oct 23, 2016 at 22:14
  • Check that your validation.js file is above the js file you are using to do the error checking, if this is in a seperate file. I had a similar issue where my js file in question validating a form on a particular page was above the validation.js file and so it threw me off a bit, with other validation error logs being highlighted in red, whilst this one wasn't. I simply moved up the js file doing the error handling below validation.js file and it worked! Hope this helps someone else too. Commented Feb 2, 2018 at 21:22

1 Answer 1

1

... it seems like the message should be in red and the border of the element will be red too!?? Do I have to style this myself...

Yes, since the plugin does not include a CSS stylesheet, you have to style this yourself.

By default, this plugin applies a class called error to the invalid element and its message label, and a class called valid to the validated element.

DEMO: jsfiddle.net/06cLoL8c/

A quick glance at the official website and you can see there are no CSS files included:

jqueryvalidation.org

From seeing other threads and sites that demo and display validation error messages it seems like the message should be in red...

These other people are likely using frameworks such as Bootstrap, which may include CSS that already targets .error and .valid classes. Otherwise, you can use the validClass and errorClass options to rename these classes into anything you wish.

Here is the same demo as above, but with ridiculous styling applied in the CSS:

jsfiddle.net/y06ur48o/

You should read the documentation for all available plugin options: jqueryvalidation.org/validate/

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

3 Comments

@user1186050, I don't know. Why not read the documentation I linked to and match up the classes accordingly?
I don't believe the effect I'm seeking (mostly the highlighting of the border with red) comes from bootstrap. I'm pretty sure it comes from some type of validation action.
@user1186050, the validation plugin does not come with CSS... it merely adds/removes the error and valid classes. Period. If you believe otherwise, merely inspect the code to confirm the fact.

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.