Skip to content
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

[4.x]: Checking keycodes in JavaScript for input validation on the Number and Money fields isn't the best. #12412

Closed
angrybrad opened this issue Dec 1, 2022 · 2 comments

Comments

@angrybrad
Copy link
Member

angrybrad commented Dec 1, 2022

What happened?

Description

Checking keycodes for JavaScript input validation on the Number and Money fields isn't the best.

Steps to reproduce

  1. On macOS, swap the keyboard layout to Hungarian.
  2. On US-based QWERTY keyboards, the layout will look like this:

CleanShot 2022-11-30 at 12 02 39

  1. On non-US QWERTY keyboards, it'll look closer to:

Screenshot 2022-11-30 at 22 33 21

  1. Notice that the 0 is to the left of 1 on non-US QWERTY keyboards and doesn't exist on US QUERTY keyboards.

  2. Trying to type the 0 on a non-US QUERTY keyboard won't input anything in a Number or Money field.

  3. Typing CTRL-Option-0 is a workaround for both non-US and US QWERTY keyboards to get it to enter a 0 successfully.

  4. Typing the three keys immediately to the right of 9 (on either a non-US or US QWERTY keyboard) will incorrectly let ö, ü, and ó pass validation and be entered into those fields (even though server-side validation fails because they are not numeric).

Relying strictly on keycodes in JavaScript isn't reliable across different keyboard layouts.

https://github.com/craftcms/cms/blob/develop/src/fields/Number.php#L258-L280

https://github.com/craftcms/cms/blob/develop/src/fields/Money.php#L254-L276

Probably worth checking the codebase for anywhere else we're checking for keycodes that need to consider localization.

Craft CMS version

4.3.4

PHP version

8.0

Operating system and version

macOS

Database type and version

n/a

Image driver and version

n/a

Installed plugins and versions

none

@brandonkelly
Copy link
Member

Fixed for the next release!

@brandonkelly
Copy link
Member

Craft 3.7.62 and 4.3.5 are out with that fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants