I want to cancel a keypress event for a long textbox so that the character newly pressed by the user is not entered in the textbox
longBox_1.addKeyPressHandler(new KeyPressHandler(){
@Override
public void onKeyPress(KeyPressEvent event) {
String Valid="1234567890";
if (!Valid.contains(String.valueOf(event.getCharCode()))) {
// the code to cancel the event to be placed here
}
}
});
If your longBox_1 is a private member of your class, or a final var, the code to cancel the event is :
Otherwise you can cast the source of the event, if you are sure it correspond to the TextBox :
Here is the doc for cancelKey :