jessepollak / card

:credit_card: make your credit card form better in one line of code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Refresh Card on Postback

jeremy-morren opened this issue · comments

I am using this plugin on an ASP.NET MVC website. I have server-side validation which is displayed on post back. The details are already filled in if there are any errors. However, since the value was set server-side the card does not 'refresh' until the relevant field is changed. Is there any Javascript that I can run on load to redraw the card?

As far as best practices go, I don't think you're supposed to be rendering your forms with CC data pre-filled like you're talking about.

If you're dead set on it, this is a super hacky way of doing it.

var elements = ['.card-number', '.card-exp', '.card-cvc', '.card-name'], e, l, evt;
for(var i = 0; i < elements.length; i++) {
  e = $(elements[i]);
  l = e.get(0);
  l.focus();
  evt = new Event('change');
  l.dispatchEvent(evt);
}

Workaround provided.