Reputation: 3752
The form is at: http://fuzzysiberians.com/app4.cfm?a=1
I am using:
$('#sec_ssn3').rules("add", {
groups: {
ssn:"sec_ssn1 sec_ssn2 sec_ssn3"
},
required:true,
number: true,
messages: {
required: " <span style='color:red;'>Please enter co-applicant's social security number</span>"
}
});
If the co-applicant checkbox is checked, I ask for co-applicants social security number. The grouping somewhat works but how do i get rid of the repeat error messages? The last one doesn't even go away once a number is entered. The ssn for primary applicant works great. On the main validate() function, I added:
errorPlacement: function(error, element) {
if (element.attr("name") == "ssn1" || element.attr("name") == "ssn2" || element.attr("name") == "ssn3" )
error.insertAfter("#ssn3");
else if (element.attr("name") == "sec_ssn1" || element.attr("name") == "sec_ssn2" || element.attr("name") == "sec_ssn3" )
error.insertAfter("#sec_ssn3");
else
error.insertAfter(element);
}
For some reason, it doesn't like that.
Upvotes: 3
Views: 2575
Reputation: 499
Looking at the documentation (http://docs.jquery.com/Plugins/Validation/validate#options) there might be a better way to set up your rules.
Example from above link:
$(".selector").validate({
rules: {
contact: {
required: true,
email: {
depends: function(element) {
return $("#contactform_email:checked")
}
}
}
}
});
Using the "depends" option you can set up validation on the element based on the coApp checkbox being checked. Try moving all the rules to the .validate() and adding
depends: function(element){ return $("#coApp").is(":checked"); }
for all the co-applicant validation.
Give that a shot and let me know.
Don't forget to revalidate/parse server side as well!
Upvotes: 5