0

I am using jQuery Validate for a form.

I have a field that is required, but I don't want to display any error message for the field. I just want the form submission to be blocked.

I have tried setting the element error message to this:

messages: {
    required: "" 
}

However, due to default validation format that I don't have access to (it is a common file that I cannot change), I still see a background/box with a blank error message.

Is there a way to hide the rendering of the error message for a specific element, while still preventing the form submission?

1
  • Show your code. Where is the HTML markup? Where is the call to .validate()? Commented Oct 2, 2014 at 3:05

1 Answer 1

1

Quote OP:

"Is there a way to hide the rendering of the error message for a specific element, while still preventing the form submission?"

See the errorPlacement callback function, which controls where messages are placed.

Use a conditional so that you return false on the specific element, which effectively prevents a message from being placed, while allowing the default message placement on the rest.

$('#myform').validate({
    rules: {
        ....
    },
    errorPlacement: function(error, element) {
        if (element.attr('name') == 'myName') {
            return false;  // no message placement
        } else {
            error.insertAfter(element); // default message placement
        }
    }
});

DEMO: http://jsfiddle.net/3cndvv3o/

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

Comments

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.