G
Gregor Kofler
The problem:
German keyboard with umlaut-keys and a "suggest" widget. Listeners for
the keyup event will fail - at least - on Opera for the umlaut-keys,
since those keys produce a keypress event, but no keyup (tested here [1]
and in my application).
Resorting to the keypress event I face another problem: Say somebody
types "foobar" and marks "bar" then presses "x". The resulting string
sent to the server for getting suggestions should be "foox", however
keypress is fired before the input element gets modified and something
like "foobarx" (element.value + String.fromCharCode(eObj.charCode)) sent.
With browser firing both keypress and keyup a combination of both
listeners will do the trick easily (get keycode/charcode in "press" and
sent in "up"). But with Opera - lacking the keyup - event, I'm stuck. I
could check for an existing selection and rebuild the string with
element value sans selected text plus typed character. But this seems
less than elegant. Any ideas for a better solution?
An old version of the widget is here [2]. It's just facilitating
keydown/keyup, but it helps to illustrate the issue.
Gregor
[1]
http://www.w3.org/2002/09/tests/keys.html
[2]
http://vxjs.gregorkofler.com/index.php?page=autosuggest
German keyboard with umlaut-keys and a "suggest" widget. Listeners for
the keyup event will fail - at least - on Opera for the umlaut-keys,
since those keys produce a keypress event, but no keyup (tested here [1]
and in my application).
Resorting to the keypress event I face another problem: Say somebody
types "foobar" and marks "bar" then presses "x". The resulting string
sent to the server for getting suggestions should be "foox", however
keypress is fired before the input element gets modified and something
like "foobarx" (element.value + String.fromCharCode(eObj.charCode)) sent.
With browser firing both keypress and keyup a combination of both
listeners will do the trick easily (get keycode/charcode in "press" and
sent in "up"). But with Opera - lacking the keyup - event, I'm stuck. I
could check for an existing selection and rebuild the string with
element value sans selected text plus typed character. But this seems
less than elegant. Any ideas for a better solution?
An old version of the widget is here [2]. It's just facilitating
keydown/keyup, but it helps to illustrate the issue.
Gregor
[1]
http://www.w3.org/2002/09/tests/keys.html
[2]
http://vxjs.gregorkofler.com/index.php?page=autosuggest