bendrucker/angular-credit-cards

cc-format does not support android

Closed this issue · 1 comments

Steps to reproduce:

  1. Go to your demo plunker
  2. add cc-format on the input field
  3. type 424242

==> Expected Result: the input field should display 4242 42
Actual Result: the input field displays 4242 24 - the last 2 numbers are inverse.

After some debugging of the code, it seems that in android, the function setCursorPostion does not behave as expected.
A quick fix would be to wrap it with $timeout. something like

function setCursorPostion (element, position) {
      $timeout( () => {
          if (element.setSelectionRange) {
             element.setSelectionRange(position, position)
         } else if (element.createTextRange) {
            var range = element.createTextRange()
            range.move('character', position)
            range.select()
        }
    },0);
}

If this is acceptable, I will open a PR with this change (and I will also fix the typo 😄 )

I'd be happy to review a PR with a minimal code change