Paste and ctrl-A broken in number-only fields in Safari and Firefox
OS: Mac OS
Browsers: Safari 8.0.4, Firefox 37.0.1
When I copy & then paste, for example, credit card information using keyboard (Cmd + V) nothing happend. No information in input and in card representation.
In Chrome and Opera - no bug.
+1
Thank you for the report and triaging, much appreciated!
I can replicate this issue — marking as a bug and will take a look. My guess is that the validation on fields like the card number and expiration restricts the keypresses to paste and/or select. If you want to take a look and open a PR, I'm happy to help in any way I can!
Not just Ctrl+A, but it seems most shortcuts stop working when the field has focus. Ctrl+W, Ctrl+T. Tested in Firefox 39.0 on Linux.
A quick look reveals the issue lies within payment.coffee keyboard handling. I did not investigate further.
Yeah, the behavior of this is all over the map, but does seem to be rooted either in restrictNumeric() or binding to keypress vs. keydown or something. I really don't know, but the behavior is erratic.
Firefox/Mac 40.0
- All modifier-key based shortcuts are blocked when a number field is active.
Safari/Mac 8.0.7
- Window/app commands (Command-T/W/Q) work, but field content modifiers (Command-C/X/V/A) don't, and probably others.
Chrome 44.0.*
- Everything seems to work fine.
Adding on to @reefdog comment.
restrictNumber() does what it is supposed to do which is to return whether the argument is a number or not. The problem with that is the method is invoked on keypress and the side effect is that it prevents the default action of non-numbers like 'v' as in 'ctrl+v' or 'cmd+v'. I actually think Safari and Firefox are correct in its interpretation of the library.
Breaking copy/paste is a huge anti-pattern and can be seen as a deal breaker for most devs.
In my opinion, If people aren't validating numbers on the backend they're doing it wrong anyway. I suggest that validation doesn't happen on keypress and the library reduces the scope of validation overall. This library should do just enough validation to change the background of the card and just enough to mask the inputs.
The documentation states:
Chrome does not fire the keypress event for known keyboard shortcuts
So if you use keypress, Chrome will not allow you to overwrite keyboard shortcuts, whereas Firefox and Safari will.
As for the actual issue, it lies within one of your dependencies. https://github.com/jessepollak/payment/blob/master/src/index.coffee#L283
The restrictNumeric function has the conditional for e.ctrlKey. I updated the js file to check for e.originalEvent.ctrlKey, and that seemed to work.
Copy and paste works. CTRL-A and CTRL-E (on macOS, that is Emacs-style, beginning of line and end of line).

Please close this issue