It seems that KeyPressHandler do not work for me, because when the
onKeyPress(..) method is called the text box has not yet updated its value.
I found this method it looks it works in FF, but i did not tested it on
other browsers. I really want these hard coded numbers for key codes to be
replaced by some gwt constants like these from KeyCodes. Please tell me what
to use instead of these hard coded values?
public static void applyNumericMask(TextBox textBox, final boolean
allowDecminal)
{
textBox.addKeyDownHandler(new KeyDownHandler(){
public void onKeyDown(KeyDownEvent keyDownEvent) {
int keyCode = keyDownEvent.getNativeKeyCode();
if ((!((keyCode > 46 && keyCode < 58)) && !((keyCode > 96 &&
keyCode < 108))) && (keyCode != (char) KeyCodes.KEY_TAB)
&& (keyCode != (char) KeyCodes.KEY_BACKSPACE)
&& (keyCode != (char) KeyCodes.KEY_ESCAPE)
&& (keyCode != (char) KeyCodes.KEY_DELETE) && (keyCode
!= (char) KeyCodes.KEY_ENTER)
&& (keyCode != (char) KeyCodes.KEY_HOME) && (keyCode !=
(char) KeyCodes.KEY_END)
&& (keyCode != (char) KeyCodes.KEY_LEFT) && (keyCode !=
(char) KeyCodes.KEY_UP) && (keyCode != 190 || !allowDecminal) && (keyCode !=
110 || !allowDecminal)
&& (keyCode != (char) KeyCodes.KEY_RIGHT) && (keyCode !=
(char) KeyCodes.KEY_DOWN)) {
keyDownEvent.preventDefault();
keyDownEvent.stopPropagation();
}
}
});
textBox.addKeyUpHandler(new KeyUpHandler(){
public void onKeyUp(KeyUpEvent keyUpEvent) {
int keyCode = keyUpEvent.getNativeKeyCode();
if ((!((keyCode > 46 && keyCode < 58)) && !((keyCode > 96 &&
keyCode < 108))) && (keyCode != (char) KeyCodes.KEY_TAB)
&& (keyCode != (char) KeyCodes.KEY_BACKSPACE)
&& (keyCode != (char) KeyCodes.KEY_ESCAPE)
&& (keyCode != (char) KeyCodes.KEY_DELETE) && (keyCode
!= (char) KeyCodes.KEY_ENTER)
&& (keyCode != (char) KeyCodes.KEY_HOME) && (keyCode !=
(char) KeyCodes.KEY_END)
&& (keyCode != (char) KeyCodes.KEY_LEFT) && (keyCode !=
(char) KeyCodes.KEY_UP) && (keyCode != 190 || !allowDecminal) && (keyCode !=
110 || !allowDecminal)
&& (keyCode != (char) KeyCodes.KEY_RIGHT) && (keyCode !=
(char) KeyCodes.KEY_DOWN)) {
keyUpEvent.preventDefault();
keyUpEvent.stopPropagation();
}
}
});
}
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.