SiberianGuy
SiberianGuy

Reputation: 25312

jQuery Validate Plugin hide/show error container

I would like to render error containers invisible and show them only when errors appear (and hide again when they disappear). What is the easiest whay to implement such behaviour?

Upvotes: 3

Views: 2339

Answers (2)

John Hartsock
John Hartsock

Reputation: 86892

The best way to implement that would to use the showerrors option.

the showerrors option allows you to define a function for how you would like your errors to display. You can manipulate this function to hide and show errors.

here are the docs

Upvotes: 2

HurnsMobile
HurnsMobile

Reputation: 4381

Set your error divs up similar to:

<div id='errors' style="display: none;">Sample Error</div>

Use jQuery's .show() method to display the div like:

if (errors == true){
    $("#errors").show()
}

If need be use .html() to customize the error like:

if (errors == specificError){
    $("#errors").html('A specific error has occurred')
    $("#errors").show()
}

And always remember, the jQuery API site is your best friend.

EDIT: I just noticed that you mention the jq validate plugin, specify which plugin you are using and I can provide more specific samples if need be.

Upvotes: 1

Related Questions