Keyboard events: keydown filtering example can't block IME-composed input (Korean/Japanese/Chinese)
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 76/100
- Loại issue
- Tài liệu
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- html, javascript
- Lĩnh vực
- documentation
Hướng nghiên cứu
Mở bài viết Keyboard: keydown and keyup và xem lại phần Default actions, đặc biệt là ví dụ về bộ lọc số điện thoại và phần thảo luận về input event trong phần giới thiệu. Thêm một ghi chú ngắn giải thích hạn chế của IME và lý do nên ưu tiên input để theo dõi hoặc xác thực văn bản được chèn, sau đó đối chiếu cách diễn đạt với ví dụ.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Article
Keyboard: keydown and keyup — the "Default actions" section, phone-number filter example:
<input onkeydown="return checkPhoneKey(event.key)" placeholder="Phone, please" type="tel">
Problem
The example (and the surrounding text) implies that returning false from keydown reliably prevents unwanted characters from being entered. That holds for direct (Latin) keyboard input, but not for languages typed through an IME (Input Method Editor), such as Korean, Japanese and Chinese.
With an IME active:
keydownfires withevent.key == "Process"(andkeyCode229), not the actual character.- More importantly, calling
preventDefault()/ returningfalseon thatkeydowndoes not cancel the text insertion, because the character is produced by the IME composition, not by the key's default action.
As a result, Korean/Japanese/Chinese characters pass straight through the filter and appear in the field. This was reported by a Korean reader of the Korean translation (ko.javascript.info), and is easy to reproduce by switching to a Korean IME and typing into the demo.
Suggestion
Add a short note after the example, along these lines:
Please note: this filter only works for direct keyboard input. Text composed via an IME (used for languages such as Korean, Japanese or Chinese) is inserted by the input method, not by the key's default action, so it can't be blocked in
keydown. That's one more reason why, for tracking or validating what actually gets into the field, theinputevent is a better choice.
This ties in nicely with the introduction of the article, which already recommends the input event for tracking input from any source.
Happy to send a PR if the note sounds good.
- Ngôn ngữ chính
- HTML
- Star
- 25.5k
- Fork
- 4k
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của javascript-tutorial/en.javascript.info
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Tất cả issue của javascript-tutorial/en.javascript.info
Issue tương tự
-
documentation help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
-
user-reported
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Kong/developer.konghq.com#7316 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
HarperFast/skills#96 ·
-
Client support matrix inclusion Đang mởenhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
infinispan/infinispan#18150 ·