card icon indicating copy to clipboard operation
card copied to clipboard

Card type doesn't change when formatting is set to false

Open dcardosods opened this issue 9 years ago • 3 comments

If I set formatting: false in the options, the card type never changes, therefore not styling the container.

Test case: http://embed.plnkr.co/cRey9SgTV2j0slM5Y8hJ/

dcardosods avatar Apr 01 '16 18:04 dcardosods

This happens because the listener that emits the cardType event (which triggers the rendering) is attached in the formatCardNumber function (see here. I'm not sure the best thing to do here. I'm open to a PR that fixes this, but I believe it will require a fair amount of refactoring for both Card and Payment.

jessepollak avatar Apr 23 '16 20:04 jessepollak

Or inside formatCardNumber, check whether formatting is enabled or not. If it's not, return cardType, otherwise continue with the rest of the function. Kinda hack but it'll work until someone submits a proper PR.

bre7 avatar Apr 24 '16 14:04 bre7

I ran into this issue, if anyone comes across this needing a quick fix, just paste this in and update your input selector to point to your cardnumber input box.

var card = new Card({ ... });
var setCardBound = card.handlers.setCardType.bind(card);
$('your cardnumber input selector').on("keyup", function (e) {
    var cardNum = e.target.value.replace(" ", "");
    var cardType = Payment.fns.cardType(cardNum);
    setCardBound(e.target, { data: cardType });
});

caesay avatar Oct 19 '16 11:10 caesay