Implement disconnect() to tidy up (remove) event listeners from the DOM when finished

This commit is contained in:
Matt-Yorkley
2021-12-20 15:25:50 +00:00
parent d58f5aa25d
commit f18fc3c2f3

View File

@@ -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) => {