From 2d96daee903c01799afde9f705e8ab12ff9a7ceb Mon Sep 17 00:00:00 2001 From: "Bradley M. Kuhn" Date: Wed, 3 Dec 2014 20:44:15 -0500 Subject: [PATCH] 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. --- www/conservancy/static/supporter-page.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/www/conservancy/static/supporter-page.js b/www/conservancy/static/supporter-page.js index 052c21f0..f424b038 100644 --- a/www/conservancy/static/supporter-page.js +++ b/www/conservancy/static/supporter-page.js @@ -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();