You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Sarkast <to...@googlemail.com> on 2008/09/01 12:41:14 UTC
Sending Ajaxrequest only if enter is pressed in a textfield
Hello,
I hope I'm not spamming this forum too much -.- I have a hard time finding
viable solutions for seemingly "easy" questions.
Currently I want a textfield which will send a request only if either enter
is pressed or when the textfield looses focus.
I have an AjaxEventBehaviour implementation which does the following:
(the action in question is "onkeydown" or "onblur" in my case
protected CharSequence getEventHandler() {
if(action.equalsIgnoreCase("onkeydown")) {
CharSequence handler = super.getEventHandler();
String check = "javascript: if (event.keyCode == 13) { ";
String endCheck = " return false; }";
return check + handler + endCheck;
}
else {
return super.getEventHandler();
}
}
This works fine, the request gets fired when I want to. However the value of
the textfield isn't up to date.
It works when I have the following
textField.add(new OnChangeAjaxBehavior() {
@Override
protected void onUpdate(AjaxRequestTarget arg0) {
//do nothing
}});
The Textfield has as a model a PropertyModel. Whenever I change something in
the textfield the value is send to the server, but I want this communication
taking place only if either enter is pressed or the textfield looses focus
(onblur). When I remove the OnChangeAjaxBehaviour then the Property "name"
isn't up to date...
I fail at putting it together the way I want to.... can someone please
help?
- Tom
--
View this message in context: http://www.nabble.com/Sending-Ajaxrequest-only-if-enter-is-pressed-in-a-textfield-tp19252434p19252434.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Sending Ajaxrequest only if enter is pressed in a textfield
Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Mon, 01 Sep 2008, Sarkast wrote:
> I have an AjaxEventBehaviour implementation which does the following:
> (the action in question is "onkeydown" or "onblur" in my case
Plain AjaxEventBehavior does not submit form data, you need
AjaxFormSubmitBehavior or AjaxFormCOmponentUpdatingBehavior
for that.
See the implementation of OnChangeAjaxBehavior for reference.
More generally, its always a good idea to have Wicket (and
other library) sources attached to your IDE, so that you can
see easily how stuff happens.
Best wishes,
Timo
--
Timo Rantalaiho
Reaktor Innovations Oy <URL: http://www.ri.fi/ >
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org