stripe-archive / jquery.payment

[DEPRECATED] A general purpose library for building credit card forms, validating inputs and formatting numbers.
MIT License
3.54k stars 684 forks source link

Can't subscribe to all input events #252

Closed adamwathan closed 7 years ago

adamwathan commented 7 years ago

Problem

Adding an 'input' listener to a field formatted as a credit card of expiry date should allow other code to observe the value of the field as it changes.

This works for cases where the library does not need to do anything special with the user input, but events are suppressed when the library needs to do special masking.

For example, when the user types "2" into a credit card field that already contains "424", no input event can be observed by outside code, which means anything watching that value still sees "424", when they should now see "4242 ".

This is because in those cases, e.preventDefault() is being called to prevent anything else from messing with the text field's value, which makes sense, but means nothing else can know when the field's value changes in these circumstances.

Proposed solution

Fire a custom event for input changes so outside code can subscribe to it and be notified of the new value.

In my fork, I'm currently just firing a payment.input event in just the cases where the default is being prevented, and then listening to the standard input event, as well as payment.input.

Since we know every time we are changing the field's value, it would be nice to fire the custom event every time the input changes (not just in the cases where the default is prevented) for consistency.

shaun-stripe commented 7 years ago

Hi @adamwathan, thanks for reporting, but we can't support any changes to the input event system right now.