Setting errorContainer multiple times on a form

I have a form $('#myForm')

that has two div $('#myDiv1')

. $('#myDiv2')

, With two text fields in each. I need one errorContainer

for each of the two divs.

If I call $('#myForm').validate({ ... });

, I can only specify one errorContainer

which is not what I want.

If I call $('#myDiv1').validate({ ... });

, I get an error message from the validate-the jquery: Uncaught TypeError: Cannot read property 'settings' of undefined

. This leads me to assume that I cannot invoke validation on anything other than a form.

Is there a way to do what I want?

+3


source to share


2 answers


You can use the following:

$("#myform").validate({
   errorPlacement: function(error, element) {}
}); 

      



Where "element" is the jQuery object of the current form input. It's at http://docs.jquery.com/Plugins/Validation/validate#toptions

+1


source


The validation method must be called on a form element.

I haven't used this in practice, but the options docs seems to indicate that you can pass multiple selectors for the errorContainer option.



$("#myform").validate({
   errorContainer: "#messageBox1, #messageBox2",
   errorLabelContainer: "#messageBox1 ul",
   wrapper: "li", debug:true,
   submitHandler: function() { alert("Submitted!") }
}); 

      

0


source







All Articles