Keyboard events: keydown filtering example can't block IME-composed input (Korean/Japanese/Chinese)
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 76/100
- Tipo di issue
- Documentazione
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Tranquilla
- Stack tecnologico
- html, javascript
- Ambito
- documentation
Direzione di ricerca
Apri l’articolo Keyboard: keydown e keyup e rivedi la sezione Default actions, in particolare l’esempio del filtro per i numeri di telefono e la spiegazione dell’input event nell’introduzione. Aggiungi una breve nota che spieghi la limitazione di IME e perché input è preferibile per monitorare o convalidare il testo inserito, quindi verifica la formulazione rispetto all’esempio.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- HTML
- Stelle
- 25.5k
- Fork
- 4k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di javascript-tutorial/en.javascript.info
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
Tutte le issue di javascript-tutorial/en.javascript.info
Issue simili
-
documentation help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
-
user-reported
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
Kong/developer.konghq.com#7316 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
HarperFast/skills#96 ·
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
infinispan/infinispan#18150 ·