Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy isn't the keypress event being sent to GWT's TextInputCell.onBrowserEvent() method?
    primarykey
    data
    text
    <h2>The question:</h2> <p>I'm overriding the GWT <code>TextInputCell.onBrowserEvent()</code> method to try and apply filtering on the characters that are typed in to the field. How can I can't get the actual character that the user typed in on a <code>keydown</code> event?</p> <h2>What I've tried:</h2> <p>I can use the <code>NativeEvent.getKeyCode()</code> method to get the key code, but this is insufficient because I want to know the specific character they typed in, so I can compare the character to a regular express. As I understand it, the keyCode just tells me the key they typed on the keyboard, so I can't discriminate between a capital 'A' and a lowercase 'a'. I can also grab the value from the <code>InputElement</code> on the <code>keyup</code> event, but this is too late, because the character has already been rendered to the UI element.</p> <p>When I call <code>NativeEvent.getCharCode()</code> it returns 0 for any character I type. I tried this on Chrome and on Firefox. Why does <code>getCharCode()</code> always return 0? Is this a bug? </p> <p>For example, here is what I tried and the values I get when I type in the number '1' on the keyboard:</p> <pre><code>event.getKeyCode() - 49 event.getCharCode() - 0 Character.toChars(event.getCharCode())[0] - (a box character because charCode was 0) String.valueOf(Character.toChars(event.getCharCode())) - (a box character because charCode was 0) String.valueOf((char) event.getKeyCode()) - 1 </code></pre> <h2>Update:</h2> <p>OK, so I see that I need to capture the <code>keypress</code> event and not <code>keydown</code>, but I print off every <code>event.getType()</code> value for every event that occurs as I type and I never see a single <code>keypress</code> event triggered. So my updated question is, why isn't the <code>keypress</code> event occurring? And if I can't capture it in the <code>TextInputCell.onBrowserEvent()</code> method, is there a different way to capture it for a <code>TextInputCell</code>. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload