notwaldorf / ama

:raising_hand: Ask @notwaldorf anything!
94 stars 13 forks source link

"Keypress is bananas" - bit of further info #16

Closed JanneM closed 9 years ago

JanneM commented 9 years ago

Tried the example code in your post "keyypress is banas". Ran Firefox 41.0.2 and Chromium WeAreTooCoolForAboutDialogs, both on Ubuntu 14.04LTS. Both work much as you describe, but with a few twists.

So, keypress events work as long as you 1) don't want to care about any language beyond English or related Western ones, any names or words with accents or diacriticals, or people using anything but a regular Latin keyboard input; and 2) don't mind that your users can trivially bypass your keypress detection at will.

Don't use it for counting characters or for input validation in general in other words. Not sure what you would use it for, seeing how it behaves.

notwaldorf commented 9 years ago

Oh my goddddddddd, it's madness all the way down. Thanks for this! I hadn't even thought about non-English languages. Keypress: not even once. :)

lozandier commented 9 years ago

@notwaldorf What are quirks you've seen in your career associated w/ beforeinput and input as substitutes to keypress and keyup?

notwaldorf commented 9 years ago

@lozandier I have never used beforeinput. My understanding is that input is fired after a character has been added to the control, which is strictly not the same as keydown/keyup: imagine that you want to prevent spaces from being added to a control: you want to do this before the space is added to the value (so on key-something), rather than adding-and-then-removing (which is what you have to do in input)