Customizing number of errors in validation plugin
I am working on a good sized form with several fields that require validation. I am using the wonderful Validation plugin created by Jörn. I have most of it working correctly. Now I need to validate a group of checkboxes, ensuring that at least one is checked. Figured out how to do that from the fiddle here:
http://jsfiddle.net/TCHYJ/
Now, my invalidHandler is not correctly reporting the number of errors. I have 12 checkboxes of which at least one needs checking and it says "You missed 12 fields. They have been highlighted below". Obviously this is incorrect. How can I change this in my invalidHandler? Here is the code for the invalidHandler:
- invalidHandler: function(e, validator) {
var errors = validator.numberOfInvalids();
if (errors) {
var message = errors == 1
? 'You missed 1 field. It has been highlighted below'
: 'You missed ' + errors + ' fields. They have been highlighted below';
$("div.errormsg span").html(message);
$("div.errormsg").show();
$('html, body').animate({scrollTop: $("#incidentFormDiv").offset().top}, 0);
} else {
$("div.errormsg").hide();
}
},
Ideally, I would like to have some sort of check in there that checks if I have only missed a single block of checkboxes and change the wording accordingly. And if there is a block of checkboxes and a single text input missing, it should say 2 errors.
Thanks!
Mike