Giter VIP home page Giter VIP logo

Comments (4)

bendrucker avatar bendrucker commented on June 13, 2024

Hmm. Not really sure what to do about this. Thanks for reporting it, but I'm not willing to add something like this without a better understanding of what's going on.

from angular-credit-cards.

SimeonC avatar SimeonC commented on June 13, 2024

I think the issue was basically the watch doesn't fire immediately. So during typing the following is entered "4111222|", then the watch fires and adds the spaces, but for some reason it decides my caret should be back one space so the end result is this "4111 22|2". I also had the same issue using the backspace button as I'd end up skipping characters instead of spaces.

from angular-credit-cards.

bendrucker avatar bendrucker commented on June 13, 2024

It fires asynchronously? If you can manage to send a PR that tests this I'm game.

from angular-credit-cards.

SimeonC avatar SimeonC commented on June 13, 2024

I got it! It was the debounce effect - see here: http://plnkr.co/edit/PLZ6PqPc3cu0v9dqfnxW?p=preview

I ended up fixing it by replacing the actual watch with this:

$element.on('input', function formatInput () {
            var input = $element.val();
            var previous = $viewValue();
            if (!input) return
            var element = $element[0]
            var formatted = card.format(card.parse(input))

            //ngModel.$setViewValue(formatted)
            var selectionEnd = element.selectionEnd
            $element.val(formatted);
            //ngModel.$render()
            if (formatted && (!formatted.charAt(selectionEnd - 1).trim())) {
              if (previous && previous.length < formatted.length) {
                selectionEnd++
              } else {
                selectionEnd--
              }
            }
            element.setSelectionRange(selectionEnd, selectionEnd)
          })

Basically this fires before any of the watchers/formatters/parsers so it can't be delayed or intercepted without hooking into the input event again.

from angular-credit-cards.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.