0

Trying to implement stripe.js Elements and one of the thing you must do is "mount" the card.

// Custom styling can be passed to options when creating an Element.
var style = {
  base: {
    // Add your base input styles here. For example:
    fontSize: '16px',
    color: "#32325d",
  }
};

// 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');

But then we have some code targeting this "card", and depending on the connection speed or some fatcors, we have errors.

We need to "wait" that the card is actually mounted and in React they actually can use Stripe React method __isMounted ( see here or here), but I don't find the equivalent or any way to "await" the card is mounted of vanilla javascript.

Mathieu
  • 4,587
  • 11
  • 57
  • 112
  • 1
    You can listen for a `ready` event, `card.on("ready",doSomething)` https://stripe.com/docs/stripe-js/reference#element-on --- though tbc the mounted element is in an iframe so you won't be able to do too much to mutate it directly. – duck Dec 02 '18 at 21:59
  • thanks yes i saw it, it's true i can "listen" with .on("ready") but what I need is more if (!card.ready) { return }...can it be done? – Mathieu Dec 02 '18 at 22:44

0 Answers0