I am working on a new layout for a page, which is a wizard-based ordering system for a client. They order sets of materials, but these materials can be grouped during the ordering process, so that they can order 10 widgets in any combination of red, blue and / or green, for example. The sum of the fields cannot exceed the previously calculated maximum. Most materials are an easy choice for each group.
I used jQuery validation on other pages, and I used the addClassRules method to validate all input elements on the page, and it worked fine. The current example I'm working on is puzzling because it only catches the first validation failure when submitting the form, but after submitting it, it usually breaks others, but never contains a complete list of validation failures.
Here is my jsfiddle example so you can see what I'm compiling: http://jsfiddle.net/brianmat/2nV5u/
I use an error counting fragment that worked on several sites without problems. In this example, I get only 1 error, even if all 7 text fields are left blank.
My only major difference here is that I am doing a rowpan to group my elements, but I do not see where this will be a problem. I know that this will end with something rather simple, but I just hit the wall at that place.
The jQuery validation code has nothing to do:
$.validator.addClassRules({
NumericInput: {
required: true
}
});
$("#theForm").validate({
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.error span").html(message);
$("div.error").show();
} else {
$("div.error").hide();
}
},
errorPlacement: function(error, element) {},
submitHandler: function(form) {
$("div.error").hide();
form.submit();
}
});
The remaining code simply processes the subtotation and numerical input data.
I am completely open to a different approach to solving this problem, so giving up my current code and finding something that works correctly is not a problem. I would rather not try to insert a square anchor into the round hole, if that is what I end up doing.