jondavidjohn / payform

:credit_card: A library for building credit card forms, validating inputs, and formatting numbers.
https://jondavidjohn.github.io/payform/
Other
427 stars 81 forks source link

How to detach events #61

Closed sergiocruz closed 5 years ago

sergiocruz commented 5 years ago

Hello there! I started using payform today and thanks for all the hard work that has been put into this so far, it's really good!

I'm using the library in an SPA environment (React), and I've noticed that there is no way to detach event listeners from elements before removing them from the DOM.

Is this something that has been discussed before? I'm happy to take a stab at opening a PR for adding a couple of new methods to the payform API but I wanted to run it by you first to see if the interest was there and what kind of approach you'd prefer.

Thanks!

EDIT: To clarify, I'm currently using this: payform.cardNumberInput(input)

jondavidjohn commented 5 years ago

Good question!

The way I've used it in the past is to not use the built in event attachment, but to use the utility functions to handle the input changes, formatting, and validation in a more "React Way".

jondavidjohn commented 5 years ago

That is not to say we'd be opposed to an API that helps to detach events!

Seems like a good idea to me. 👍

ddayguerrero commented 5 years ago

I don't see any outstanding issues with this as well!

sergiocruz commented 5 years ago

Thanks for getting back to me so quickly @jondavidjohn and @ddayguerrero! I went ahead and created a PR allowing us to detach events from the input fields. Please let me know if you would have done it any differently, etc.

The PR I am referring to is #62 just in case. Thanks again!