My workaround was this. The idea is to add a submit behavior to the text
field, and it fires that only when user hits enter.
This code is inside the form's constructor.
searchCriteria = new TextField("searchCriteria", new Model(""));
searchCriteria.add(new AjaxFormSubmitBehavior(this, "onkeypress") {
protected void onSubmit(AjaxRequestTarget target) {
//submit code
}
protected CharSequence getEventHandler() {
CharSequence handler = super.getEventHandler();
String check = "javascript: if (event.keyCode == 13) { ";
String endCheck = " return false; }";
return StringUtils.join(new Object[] { check, handler, endCheck });
}
});
What do you think?
Regards!
Juan