enumerar todos los mensajes de error en un contenedor con validación de jquery

I want validation messages to be added to a container above my form in a list instead of next to the field. What I have so far works for the most part. As the user enters invalid info into fields, validation messages are added to the container in a list. The problem is that if the user goes to a field and enters valid data, the whole error list is hidden and does not come back until you click on a field which has an error. I need the error list to stay displayed and as the user fixes the fields, the corresponding messages disappear.

Here is how I set up my .validate

$("#myform").validate( {
    onSubmit : false,
    errorContainer : '#message',
    errorLabelContainer : '#message',
    errorElement : "li",
});

And then accordingly I have a UL above my form with id "error"

¿Cómo hago para que esto funcione?

preguntado el 01 de febrero de 12 a las 22:02

¿Puedes configurar un jsFiddle or give us more of your code? There isn't really enough information in your question to help you. -

1 Respuestas

You can create your own error array using the errorList function of the plugin

 var summary = "";    
    jQuery.each(errorList, function() { summary += this.message + '<br />' +"\n"; });

Con

.html(summary)

you can add the errors to an hidden error container: here is the relevant part of the code from a recent project:

$("#commentForm").validate({
            showErrors: function(errorMap, errorList) {
                if (submitted) {
                    var summary = "";
                    jQuery.each(errorList, function() { summary += this.message + '<br />' +"\n"; });
                    var errorContainer = jQuery('#myErrorContainer');
                    errorContainer.fadeIn().html(summary);
                    submitted = false;
                }
            },      

Respondido el 18 de diciembre de 12 a las 21:12

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.