Description: Fixes Issue #1386 The TextBox example gives a bad example of limiting input to numeric only values because it doesn't allow any navigational input from arrow keys, backspace, delete, and similar. It literally allows nothing but numeric values. Fix: Per Joel's example, I added more clauses to the if statement to allow the following keys in addition to numeric keys: backspace, delete, enter, home, end, left, right, up, and down For these keys, I used the static values in the KeyboardListener class instead of hardcoding keyCodes into the example. Patch by: rshearer,jlabanca Review by: jgw git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@1284 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/javadoc/com/google/gwt/examples/TextBoxExample.java b/user/javadoc/com/google/gwt/examples/TextBoxExample.java index 5f2041e..34c908b 100644 --- a/user/javadoc/com/google/gwt/examples/TextBoxExample.java +++ b/user/javadoc/com/google/gwt/examples/TextBoxExample.java
@@ -35,7 +35,12 @@ // Let's disallow non-numeric entry in the normal text box. tb.addKeyboardListener(new KeyboardListenerAdapter() { public void onKeyPress(Widget sender, char keyCode, int modifiers) { - if (!Character.isDigit(keyCode)) { + if ((!Character.isDigit(keyCode)) && (keyCode != (char) KEY_TAB) + && (keyCode != (char) KEY_BACKSPACE) + && (keyCode != (char) KEY_DELETE) && (keyCode != (char) KEY_ENTER) + && (keyCode != (char) KEY_HOME) && (keyCode != (char) KEY_END) + && (keyCode != (char) KEY_LEFT) && (keyCode != (char) KEY_UP) + && (keyCode != (char) KEY_RIGHT) && (keyCode != (char) KEY_DOWN)) { // TextBox.cancelKey() suppresses the current keyboard event. ((TextBox)sender).cancelKey(); }