From a8afe7fee36b6a9417f00230755bb7ed438be786 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Fri, 1 Apr 2022 15:58:20 +0200 Subject: [PATCH] Use requestSubmit() method for actually submit the form with event ... that could be catch by turbo (and then handled by cable_ready) `this.catchFormSubmit` avoid infinite loop then --- app/webpacker/controllers/stripe_controller.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/webpacker/controllers/stripe_controller.js b/app/webpacker/controllers/stripe_controller.js index 3a1f3f459b..e44762dd08 100644 --- a/app/webpacker/controllers/stripe_controller.js +++ b/app/webpacker/controllers/stripe_controller.js @@ -15,6 +15,7 @@ export default class extends Controller { initialize() { this.parentForm = this.pmIdTarget.form; + this.catchFormSubmit = true; // Initialize Stripe JS this.stripe = Stripe(this.data.get("key")); @@ -40,7 +41,7 @@ export default class extends Controller { // Before the form is submitted we send the card details directly to Stripe (via StripeJS), // and receive a token which represents the card object, and add that token into the form. stripeSubmit = (event) => { - if(!this.stripeSelected()) { return } + if(!this.stripeSelected() || !this.catchFormSubmit) { return } event.preventDefault(); event.stopPropagation(); @@ -54,8 +55,8 @@ export default class extends Controller { this.expYearTarget.setAttribute("value", response.paymentMethod.card.exp_year); this.brandTarget.setAttribute("value", response.paymentMethod.card.brand); this.last4Target.setAttribute("value", response.paymentMethod.card.last4); - - this.parentForm.submit(); + this.catchFormSubmit = false; + this.parentForm.requestSubmit(); } }); }