Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between errorContainer and errorLabelContainer options in jQuery Validate

Using ErrorLabelContainer I can display all the errors on my page in a single div.

What is the use of errorContainer?

like image 667
user2961938 Avatar asked Aug 14 '14 18:08

user2961938


People also ask

How do you check whether a form is valid or not in jQuery?

$("#form_id"). valid(); Checks whether the selected form is valid or whether all selected elements are valid. validate() needs to be called on the form before checking it using this method.

What is jQuery validate unobtrusive?

An unobtrusive validation in jQuery is a set of ASP.Net MVC HTML helper extensions.By using jQuery Validation data attributes along with HTML 5 data attributes, you can perform validation to the client-side.

What is jQuery validate used for?

The jQuery Validate is a feature provided by jQuery that makes it easier for the creator to validate the user or visitor's input data while keeping your code free of all the mesh of validation rules from javaScript code.

How do I change the color of my validation message?

If you are looking to change colors of text/background of your validation error messages, while there is no built-in method for changing the colors, you can absolutely change this with a little CSS! Just go to the Style tab and scroll to the bottom of the survey preview and click the link to access to HTML/CSS Editor.


1 Answers

Please refer to official documentation where all this is clearly explained.

errorLabelContainer - All error labels are displayed inside an unordered list with the ID “messageBox”, as specified by the selector passed as errorContainer option.

In other words, as an example, the errorLabelContainer contains the errors as an unordered list. This unordered list goes inside of the errorContainer.

Example usage:

$('form').validate({
    errorContainer: "#messageBox1",
    errorLabelContainer: "#messageBox1 ul",
    wrapper: "li"
});

Will yield this markup...

<div id="messageBox1">                 <!- errorContainer ->
    <ul>                               <!- errorLabelContainer ->
        <li>Field is required</li>     <!- wrapper ->
        <li>Enter a valid email</li>   <!- wrapper ->
    </ul>
</div>

To play around with how this works, you could create a jsFiddle demo and inspect the DOM to see how the rendered HTML is constructed.

like image 115
Sparky Avatar answered Oct 10 '22 10:10

Sparky