jQuery validate showerrors display name

logistef picture logistef · Nov 7, 2011 · Viewed 7.9k times · Source

I would like to add the name of the errors to my function so users know which fields they have to check.

This is my current function:

showErrors: function(errorMap, errorList) {
            var summary = "Please check following errors:";
            $.each(errorList, function() {
                summary += " * " + this.message + "<br>" ;
            });
            $('.errorbox').html(summary);
            this.defaultShowErrors();
        },
        submitHandler: function() {
            alert("submitted!");
        }
    });

How can I do this?

Answer

Rory McCrossan picture Rory McCrossan · Nov 7, 2011

As you are using the Bassistance.de validation plugin, the easiest option to you is to add a friendly insturction message to the title parameter to each input control. This message will then be used as instruction text in the error message which appears. Here is an updated fiddle showing how this works: http://jsfiddle.net/xTdYr/3/

Alternatively, you can manually add the rules in the instanciation call of the .validate() method by using the messages parameter, details here: http://docs.jquery.com/Plugins/Validation/rules