PDA

View Full Version : Pressing "enter" in field to submit form causes field's BaseModel not to be updated



citress
5 May 2010, 3:18 PM
I'm using FormBinding to bind fields on a page to a BaseModel object, and also using a KeyNav to capture the Enter key press in order to submit the page on enter. If I hit "enter" when the focus is still inside the field (without leaving focus from the field), the field value is not updated into the BaseModel object. It looks like FieldBinding.bind() is triggered by an onBlur event, so if I his "enter" without ever leaving the field, the value from the field is not updated into the bound model object. If I click outside of the field and back into the field, then it works.

How should I handle this issue?



public void onModuleLoad() {

FormPanel formPanel = new FormPanel();
TextField<String> name = new TextField<String>();
name.setFieldLabel("Name");
name.setName("username");

formPanel.add(name);

final BaseModel model = new BaseModel();
FormBinding formBinding = new FormBinding(formPanel, true);
formBinding.bind(model);

new KeyNav<ComponentEvent>(formPanel) {
@Override
public void onEnter(ComponentEvent ce) {
Window.alert((String) model.get("username"));
}
};

RootPanel.get().add(formPanel);
}