PeraMika
PeraMika

Reputation: 3688

jQuery Validate - display one warning for the same types of errors

I have a simple form that has several input elements that are required:

$("input").each(function(index, elem) {
   var rules = {
     required:true
   }
   $(elem).rules("add", rules);
});    

And I want to place all error messages in some div, like this:

    <div id="errorContainer" class="inputGreska">
        There are some errors. Please correct the following:
        <ul id="errorLabelContainer"></ul>
    </div>    

So, I did the following:

    $("#forma").validate({
       errorClass: "red",
       errorContainer: "#errorContainer",
       errorLabelContainer: "#errorLabelContainer",
       wrapper: "li",
       errorElement: "div"
    });    

The problem is the following:

If the user forgets to fill more than one input - within error container there will be the same warnings repeated. So, if the user forgets to fill 3 fields, there will be:

Is it possible to show just one error message, like this:

Thank you.

Upvotes: 1

Views: 916

Answers (1)

naav
naav

Reputation: 123

If i understand you're question right you are wanting to display one error message for a form validation even though it has multiple errors, i would try using the showErrors() callback defined in JQuery validate.

showErrors: function (errorMap, errorList) { $("#errorContainer").html("Please enter all required fields with an asterisk*."); }

Have pulled together a quick fiddle to show you a working example http://jsfiddle.net/mvz0c2am/ , hope this helps.

Upvotes: 1

Related Questions