Reputation: 795
I am new to GWT and would like to add a simple keyboard shortcut to a 'Yes' button in a dialog popup in our application? I have looked around and can not seem to find clear way of adding one.
thank you for any help.
Upvotes: 2
Views: 413
Reputation: 41089
Override onPreviewNativeEvent method in your dialog:
@Override
protected void onPreviewNativeEvent(NativePreviewEvent event) {
super.onPreviewNativeEvent(event);
if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) {
hide();
}
if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
// submit(); - or whatever you need to do here
}
}
Upvotes: 4