Stripe elements on Change event issue

2.7k Views Asked by At

Hi i regenerate token with every credit card change for cc input field, tried event on change and addEventListener('change')

 card.addEventListener('change', function(event) {
         //billingDataChange();
   })

and

 card.on('change', function(event) {
     //billingDataChange();
   });

Noticed that this event is fired only when you start to type first and last letter, so if you change number in the middle, or when you paste code, token won't be regenerated. Any idea how to solve this issue, maybe with different event or something else

1

There are 1 best solutions below

0
On

With Stripe v3 (at least), if you use the code

var card = elements.create('card')
card.on('change', function(event) {
    //billingDataChange();
});

It should fire correctly. If you manually query the card via a selector, the on change event won't work since stripe adds sub-elements and you won't be referencing the actual element that gets changed.