I have a user login form that I want submitted if the user presses ENTER in 
the password field or clicks the login button. So I add a KeyDownHandler:

KeyDownHandler kdh = new KeyDownHandler() { 
  @Override 
  public void onKeyDown(KeyDownEvent event) { 
    if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { 
      event.stopPropagation(); 
      login_btn.click(); 
    } 
  } 
}; 
password.addKeyDownHandler(kdh); 

The login button calls the presenter to doLogin(). Before sending the 
request to the server, the method checks that the fields are filled in. If 
not, an alert is popped up.

I want this alert to hide on ENTER or ESC, so the alert has a method:

@Override 
public void onPreviewNativeEvent(Event.NativePreviewEvent event) { 
  Event nativeEvent = Event.as(event.getNativeEvent()); 
  int c = nativeEvent.getKeyCode(); 
  if (c==KeyCodes.KEY_ENTER || c==KeyCodes.KEY_ESCAPE) { 
    hide(); 
  }
}

Problem: The alert pops up and disappears all on a single ENTER.

Why isn't Event.stopPropagation() stopping the ENTER key? Why should I even 
need to try since the alert is only created when the error is detected? How 
can I accomplish this (other than Window.alert())?

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to