From 0f540e11a865b5ba7caef0d6053af6fd473a3466 Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" <mjw@mjwconsult.co.uk> Date: Thu, 14 Mar 2019 21:53:40 +0000 Subject: [PATCH] Fix webform detection so it doesn't generate a false positive if we also have a webform on the same page --- js/civicrm_stripe.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/js/civicrm_stripe.js b/js/civicrm_stripe.js index 658e66e4..0260fedd 100644 --- a/js/civicrm_stripe.js +++ b/js/civicrm_stripe.js @@ -185,7 +185,7 @@ CRM.$(function($) { } }); - var isWebform = getIsWebform(); + var isWebform = getIsWebform($form); // For CiviCRM Webforms. if (isWebform) { @@ -222,7 +222,7 @@ CRM.$(function($) { return false; } - var isWebform = getIsWebform(); + var isWebform = getIsWebform($form); // Handle multiple payment options and Stripe not being chosen. if (isWebform) { @@ -341,17 +341,19 @@ CRM.$(function($) { } } - function getIsWebform() { - return $('.webform-client-form').length; + function getIsWebform(form) { + // Pass in the billingForm object + // If the form has the webform-client-form class then it's a drupal webform! + return form.hasClass('webform-client-form'); } function getBillingForm() { // If we have a stripe billing form on the page var $billingForm = $('input#stripe-pub-key').closest('form'); - if (!$billingForm.length && getIsWebform()) { + //if (!$billingForm.length && getIsWebform()) { // If we are in a webform - $billingForm = $('.webform-client-form'); - } + // $billingForm = $('.webform-client-form'); + //} if (!$billingForm.length) { // If we have multiple payment processors to select and stripe is not currently loaded $billingForm = $('input[name=hidden_processor]').closest('form'); @@ -361,7 +363,7 @@ CRM.$(function($) { function getBillingSubmit() { $form = getBillingForm(); - var isWebform = getIsWebform(); + var isWebform = getIsWebform($form); if (isWebform) { $submit = $form.find('[type="submit"].webform-submit'); -- GitLab