-
-
Notifications
You must be signed in to change notification settings - Fork 188
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
Prevent non-numeric input in contesting-serial fields #3023
Conversation
Your code is generally correct and will prevent non-numeric input. However, there are a few potential issues to consider: Accessibility: Some users might use the keyboard to navigate, and your current code would prevent the use of keys like Tab, Backspace, and Arrow keys. You might want to allow these keys. Copy and Paste: Users can still paste non-numeric characters into the input field. If you want to prevent this, you'll need to handle the paste event. Non-Standard Keys: Some keyboards might have non-standard keys that produce a character code less than 48 or greater than 57. This is rare, but it's something to keep in mind.
This version allows the Tab (9), Backspace (8), Left Arrow (37), and Right Arrow (39) keys. It also prevents pasting non-numeric characters. |
Thanks for putting focus on accessibility, although all mentioned keys and pasting did work in Firefox as well as in Chrome in my tests. Which browser did you use? The numpad-keys e.g. may have different keyCodes and that's why the code does not test on |
It was just pseudo code again, didn't test it. I'll see if I can get it working today |
Uh oh! @patrickrb, the image you shared is missing helpful alt text. Check #3023 (comment). Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image. Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs. |
Thanks for your feedback. I have changed the title to avoid confusion, which fields are meant. I could enter arbitrary data with Firefox into the 'numbers'-field, which got discarded without any mention. Do I understand it right, that issues with control-keys weren't experienced but assumed by you? Again: I can not reproduce issues with control keys. p.s. Uh yeah! I'd definitly go for a smiley in one of my next signal reports ;). |
I didnt give much thought for emjoiis being added! |
Firefox allows non-numeric input in
type=number
-inputs. This PR adds/modifies code to prevent this by checking the codepoint of the keyboardEvent.