Rework Javascript final form validation.

The problem before was that an error in the annual form would prevent
submission of the monthly form and vice-versa.  That is herein corrected
with this change, which assures that the input with id of "amount" if
the specific form (id'd with "annual" or "monthly") is the only one
checked.
This commit is contained in:
Bradley M. Kuhn 2014-12-03 20:44:15 -05:00
parent 9c40bf2e60
commit 2d96daee90

View file

@ -64,15 +64,21 @@ $(document).ready(function() {
errorElement.removeClass("form-error").addClass("form-error-show");
}
});
$("#supporter-form-submit").click(function(event){
var valid = $('.amount').hasClass("valid");
if (! valid) {
$("#form-correction-needed").removeClass("form-error").addClass("form-error-show")
var validateFormAtSubmission = function(element, event) {
var valid = element.hasClass("valid");
if (! valid) {
$("#form-correction-needed").removeClass("form-error").addClass("form-error-show")
.css("font-weight", "bold").css("font-size", "150%");
event.preventDefault();
} else {
$("#form-correction-needed").removeClass("form-error-show").addClass("form-error");
}
event.preventDefault();
} else {
$("#form-correction-needed").removeClass("form-error-show").addClass("form-error");
}
};
$(".supporter-form-submit#monthly").click(function (event) {
validateFormAtSubmission($(".supporter-form#monthly input#amount"), event);
});
$(".supporter-form-submit#annual").click(function (event) {
validateFormAtSubmission($(".supporter-form#annual input#amount"), event);
});
/* Handle toggling of annual/monthly form selections */
$('.supporter-type-selection#monthly').hide();