52

I'm using jQuery Validate, but I really don't want to have any error messages whatsoever. Rather, I need to have red boxes around offending inputs/selects/etc. These red boxes were a piece of cake to add, but I still cannot remove error messages themselves. How do I disable them altogether?

3 Answers 3

146

Use a custom error placement function (see the plugin's options) that doesn't append the error message to anything.

$('#form').validate({
  errorPlacement: function(error,element) {
    return true;
  }
});

Or you could put the error messages elsewhere on the page - say in a DIV at the top of the page.

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

3 Comments

Thanks, found this answer while having the same problem :)
@tvanfosson, It it OK to use CSS like this: label.error {display:none !important;}
@RainLover That wouldn't override any styles set directly on the element. I'd have to look to see how the plugin normally does the display. If it's entirely class-based it would work but if it uses show/hide then it wouldn't. It would also force you into a global solution (assuming a single site-wide style sheet).
10

You can override the showErrors function:

jQuery('form').validate({
    showErrors: function(errorMap, errorList) {
        // Do nothing here
    },
    onfocusout: false,
    onkeyup: false,
    rules: {
        email: {
            required: true
        }
    },
    messages: {
        email: {
            required: 'The email is required'
        }
    }
});

2 Comments

Won't that also eliminate highlighting the element?
@tvanfosson: Yes, it actually does.
9

This is how I do it. Just put $.validator.messages.required = ''; before your call to initialise validate() i.e.:

$.validator.messages.required = '';
$('#formData').validate({});`

This will make it show the styles on the inputs, but no message labels!

1 Comment

You will still need label.error {display:none !important;} since the empty boxes take up space.

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.