richnologies / ngx-stripe

Angular 6+ wrapper for StripeJS
MIT License
219 stars 77 forks source link

Real Time Validation #23

Closed jculverwell closed 6 years ago

jculverwell commented 6 years ago

Thank you for a great project.

I have a question about real time validation. If you refer to https://stripe.com/docs/stripe-js

They show an example using real time validation.

// Create an instance of the card Element.
var card = elements.create('card', {style: style});

// Add an instance of the card Element into the `card-element` <div>.
card.mount('#card-element');

// Handle real-time validation errors from the card Element.
card.addEventListener('change', function(event) {
  var displayError = document.getElementById('card-errors');
  if (event.error) {
    displayError.textContent = event.error.message;
  } else {
    displayError.textContent = '';
  }
});

I tried to do something similar but noticed the card.on function does not have an event argument which is required for displaying the event error message.

this.card = this.elements.create('card', {
            style: {
              base: {
                fontSize: '1.5rem'
              }
            }
          });
          this.card.mount('#card-element');

          this.card.on('change', () => {

          });

Just wondering if I am missing something or if you had any suggestions.

richnologies commented 6 years ago

Which version of the module are you using? Because I am aware that in previous versions the argument was missing, but in the current version is optional, to be compatible with other events that don't need the parameter, but is there.

Here is a stackblitz link with some test using the event:

https://stackblitz.com/edit/angular-2fznkr

But is basically the same code you're using.

Hope it help

PD: As you can see in the code, all the results are shown in the console

jculverwell commented 6 years ago

Thank you so much, I had an older version and once I updated it all works as expected. Might be worth including the realtime validation in the example in the readme.

Thanks again

richnologies commented 6 years ago

Thanks @jculverwell, I already did, it will be included in future versions

jculverwell commented 6 years ago

Thank you, really appreciate your responsiveness