From f18fc3c2f38eda23b4cc9f9e0d4bb6806eaf8a19 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Mon, 20 Dec 2021 15:25:50 +0000 Subject: [PATCH] Implement disconnect() to tidy up (remove) event listeners from the DOM when finished --- app/webpacker/controllers/stripe_controller.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/webpacker/controllers/stripe_controller.js b/app/webpacker/controllers/stripe_controller.js index a7fe9e52a8..940093642b 100644 --- a/app/webpacker/controllers/stripe_controller.js +++ b/app/webpacker/controllers/stripe_controller.js @@ -32,6 +32,11 @@ export default class extends Controller { this.stripeElement.addEventListener("change", this.updateErrors); } + disconnect() { + this.parentForm.removeEventListener("submit", this.stripeSubmit); + this.stripeElement.removeEventListener("change", this.updateErrors); + } + // 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) => {