jessepollak / card

:credit_card: make your credit card form better in one line of code
MIT License
11.67k stars 1.48k forks source link

Refreshing the Credit Card Image #471

Open dcipher opened 4 years ago

dcipher commented 4 years ago

I have the masked Credit Card No ( **** 1234), expiry and Name stored on a cell phone. When the user wants to update their credit card information it would be nice if the form showed the currently saved values without having the user enter data in each field. So is there a way to cause the form to refresh using the values in the pre-loaded fields?

sergeykonovalenko commented 3 years ago

I have the same problem

melloware commented 3 years ago

I use JQuery and this works for me to show the card with the values that are prefilled updated.


$(document).ready(function() {
    const blur = new Event('blur');
    const change = new Event('change');
    $('form').find(':input').each(function() {
        if (this.name === "number" || this.name === "name" || this.name === "expiry" || this.name === "cvc") {
            this.dispatchEvent(blur);
            this.dispatchEvent(change);
        }
    })
});

This assumes your field names are like mine above. Works like a charm

ronaldohoch commented 3 years ago

Same here. But, used the solution provided by melloware.

Angular code: this.nameInput.nativeElement.dispatchEvent(new Event('change'));

But, when set the input to empty, this doesn't work, tried these events: change, keydown, keyup, blur, keypress.

melloware commented 3 years ago

@ronaldohoch and you are using the latest version found in the /dist folder here? Just making sure its not already fixed as we have committed some fixes since the 2.5.0 release that is on NPM.

melloware commented 3 years ago

Also I think I had to fire BOTH blur and change to make it work.

ronaldohoch commented 3 years ago

Due Content Security Policy, i need to download the file '-' Is this the new version?

https://unpkg.com/card@2.5.0/dist/card.js

melloware commented 3 years ago

No this 2.5.1 is not published to NPM yet: https://github.com/jessepollak/card/tree/master/dist

melloware commented 3 years ago

You can see what has been fixed in 2.5.1 here: https://github.com/jessepollak/card/milestone/2?closed=1

ronaldohoch commented 3 years ago

Worked!

Thank you :)