Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stripe elements on Change event issue

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

like image 805
vladimirProp Avatar asked Sep 01 '25 06:09

vladimirProp


1 Answers

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.

like image 190
Phillip Avatar answered Sep 02 '25 19:09

Phillip