Paul
Paul

Reputation: 26660

jQuery validation - how to remove common message

I made common validation message ("You have errors on page") using "invalidHandler" option. Now I'm looking for a way to remove this message (on leave control) when all the fields will become valid.

Upvotes: 3

Views: 884

Answers (2)

charlietfl
charlietfl

Reputation: 171679

The invalidHandler option over rides the internal plugin error handling that adds and removes errors automatically. If all you are doing is setting the message in the option, you would do better removing the option.

The plugin is so flexible that to a certain degree it depends on what you are asking of the invalidHandler and the behavior s you want from your validation process

You can override the default messages this way

$.validator.messages.required='My Required message';

Upvotes: 0

Andrew Whitaker
Andrew Whitaker

Reputation: 126052

Using invalidHandler is one way to do this, but if you use the errorContainer option, jQuery validate will take care of hiding and showing the message for you. For example:

Html:

<form id="test">
    <label for="name">Name</label>
    <input id="name" type="text" name="name" class="required"/>

    <label for="age">Age</label>
    <input id="age" type="text" name="age" class="required"/>

    <input type="submit" />
</form>

<div id="invalid">You have errors the on page</div>​

CSS

#invalid { display: none; }

JavaScript:

$("#test").validate({
    errorContainer: "#invalid"
});

Example: http://jsfiddle.net/andrewwhitaker/deArQ/

Upvotes: 5

Related Questions