Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

format credit card number after Autofill #155

Closed
jack-guide opened this issue Jun 8, 2021 · 12 comments · Fixed by #156
Closed

format credit card number after Autofill #155

jack-guide opened this issue Jun 8, 2021 · 12 comments · Fixed by #156
Assignees
Labels
Milestone

Comments

@jack-guide
Copy link

Hi,

is there a way to format the credit card number after Autofill by the browser.

e.g. the user has their card details saved in chrome / Edge etc and is prompted to use it when they enter the credit card field. the Autofil enters the card number without spaces e.g. 4444333322221111 and it is not automatically formatted to 4444 3333 2222 1111.

if you paste 4444333322221111 into the credit card box it does format it 4444 3333 2222 1111.

thanks for your help.

very useful library

jack

@jack-guide jack-guide changed the title formal credit card number after Autofill format credit card number after Autofill Jun 8, 2021
@melloware
Copy link
Collaborator

Hmmmm i would assume autofill would fire the change event. If you do some research on what event is fired on autofill we might be able to fix it.

@jack-guide
Copy link
Author

the following fires:

$("[id*='CCInputFieldName']").on('blur input', function () {
alert();
});

but i do not think i have access to a function to format the input box

thanks for replying

@melloware
Copy link
Collaborator

Weird these are the DOM events mapped to the field... Looks like formatCardNumber is called on "input" but not on "blur" but i thought "input" should cover it?

  @formatCardNumber: (el, maxLength) ->
    Payment.restrictNumeric el
    QJ.on el, 'keypress', restrictCardNumber(maxLength)
    QJ.on el, 'keypress', formatCardNumber(maxLength)
    QJ.on el, 'keydown', formatBackCardNumber
    QJ.on el, 'keyup blur', setCardType
    QJ.on el, 'paste', reFormatCardNumber
    QJ.on el, 'input', formatCardNumber(maxLength)

@jack-guide
Copy link
Author

CC Autofil

that is a bit beyond my technical knowledge.

at the moment autofill is unformatted like this

@jack-guide
Copy link
Author

CC Manual Entry

when i manually key them in, its formatted correctly.

the same is true if i paste 4444333322221111

@melloware melloware self-assigned this Jun 9, 2021
@melloware melloware added the bug label Jun 9, 2021
@melloware melloware added this to the 2.4.4 milestone Jun 9, 2021
melloware added a commit to melloware/payment that referenced this issue Jun 9, 2021
melloware added a commit to melloware/payment that referenced this issue Jun 9, 2021
@melloware melloware linked a pull request Jun 9, 2021 that will close this issue
@melloware
Copy link
Collaborator

Can you try something. Can you edit your payment.js locally and try it. I already had the input event so I added a blur event to reformatCardNumber. Which is similar to the 2 Jquery events you have above.

Payment.formatCardNumber = function(el, maxLength) {
    Payment.restrictNumeric(el);
    QJ.on(el, 'keypress', restrictCardNumber(maxLength));
    QJ.on(el, 'keypress', formatCardNumber(maxLength));
    QJ.on(el, 'keydown', formatBackCardNumber);
    QJ.on(el, 'keyup blur', setCardType);
    QJ.on(el, 'blur', reFormatCardNumber);
    QJ.on(el, 'paste', reFormatCardNumber);
    QJ.on(el, 'input', formatCardNumber(maxLength));
    return el;
  };

I added the line

    QJ.on(el, 'blur', reFormatCardNumber);

@jack-guide
Copy link
Author

perfect! that worked

genius

melloware added a commit that referenced this issue Jun 10, 2021
* Fix #155: Browser Autofill format card number
@melloware
Copy link
Collaborator

Thanks for testing fixed for 2.4.4

@jack-guide
Copy link
Author

rockstar

@melloware
Copy link
Collaborator

I have to revert this change as it broke mobile browsers see #161

@osrl
Copy link

osrl commented May 29, 2022

I still have this issue on 2.4.6

@melloware
Copy link
Collaborator

Yes see my comment above that is had to be reverted because it broke mobile browsers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants