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?
source to share
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
source to share
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!") }
});
source to share