3

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?

2 Answers 2

2

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

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

Comments

1

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.

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.