views:

125

answers:

1

Hi everyone, I have a form that is being valdated with the Jquery Validation Plugin. I have managed to get a centeral message "Please Recheck the form", and to have the input focus on the first error. To get this, I had to override the default message of each of the errors. I was wondering if anyone could help me figure out how I can have it display the error message associated with the first error input instead of a general error message. Here is the code:

$("#Help-A-Noobie-Form" ).validate({

 invalidHandler: function(form, validator) {      
     $(this).find(":input.error:first").focus();
     var message = 'Please Recheck The Form' ;
    $("#Help-A-Noobie-Form #Message p").addClass('red').html(message);        
   },

showErrors: function(errorMap, errorList) {

this.defaultShowErrors(); },

rules: { required:true, email: {email:true}, phone: {digits:true}
},

messages: { email: "", phone: "", lastname: "", firstname: "", required:"" } })

A: 
$("#Help-A-Noobie-Form" ).validate({
    onfocusout: false,
    onkeyup: false,
    showErrors: function(errorMap, errorList) {
        if (errorList.length > 0) {
            jQuery('.errors').html('<div id="error" class="erreur">' + errorList[0].message + '</div>');
        }
    }, 
    rules: {
        email: { email:true },
        phone: { digits:true }
    },  

    messages: { 
        email: { email: 'please enter a valid email' },
        phone: { digits: 'please enter a valid phone' }
    }
});
Darin Dimitrov
Thank you! I'll try it out
Iamjon