From 179da37bbc0f069e36a2263941b0723357d421e4 Mon Sep 17 00:00:00 2001 From: Jamie McClelland <jm@mayfirst.org> Date: Wed, 25 Apr 2018 15:08:36 -0400 Subject: [PATCH] ensure our js code always runs first If we wait for the event handler to kick in, other js code might run first (like offline event registration does an ajax call to register a participant). --- js/civicrm_stripe.js | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/js/civicrm_stripe.js b/js/civicrm_stripe.js index 6d4fd698..43ebf2a5 100644 --- a/js/civicrm_stripe.js +++ b/js/civicrm_stripe.js @@ -99,8 +99,28 @@ }); $submit.click( function() { + // Take over the click function of the form. debugging('clearing submit-dont-process'); $form.data('submit-dont-process', 0); + + // Run through our own submit, that executes Stripe submission if + // appropriate for this submit. + var ret = submit(event); + if (ret) { + // True means it's not our form. We are bailing and not trying to + // process Stripe. + // Restore any onclickAction that was removed. + $form = getBillingForm(); + $submit = getBillingSubmit(); + $submit.attr('onclick', onclickAction); + $form.get(0).submit(); + return true; + } + // Otherwise, this is a stripe submission - don't handle normally. + // The code for completing the submission is all managed in the + // stripe handler (stripeResponseHandler) which gets execute after + // stripe finishes. + return false; }); // Add a keypress handler to set flag if enter is pressed @@ -138,23 +158,6 @@ $form.find("input#cvv2").val(''); } - // Intercept form submission. - $form.on('submit', function(event) { - var ret = submit(event); - if (ret) { - // True means it's not our form. We are bailing and not trying to - // process Stripe. - // Restore any onclickAction that was removed. - $form = getBillingForm(); - $submit = getBillingSubmit(); - $submit.attr('onclick', onclickAction); - $form.get(0).submit(); - return true; - } - // Otherwise, this is a stripe submission - don't handle normally. - return false; - }); - function submit(event) { event.preventDefault(); debugging('submit handler'); -- GitLab