If you have multiple html text input elements you can insert the javascript below in your document etc.... The only thing new in wicket is that you simply need to add a callback to your java method, which you can learn about here (I made a video for this type of issue): http://www.youtube.com/watch?v=aqNQShdSOvM http://www.youtube.com/watch?v=aqNQShdSOvM
left out of your code post, but you should need an AjaxFormSubmitBehavior("onkeydown") as Martin pointed out, so for other users you should post a more complete solution instead of simply "script". But everyone does appreciate you left something for the next person. function cancelEvent(event){ event.cancelBubble = true; if (event.stopPropagation) event.stopPropagation(); } if (typeof window.event == 'undefined'){ document.onkeypress = function(e){ var test_var=e.target.nodeName.toUpperCase(); if (e.target.type) var test_type=e.target.type.toUpperCase(); if ((test_var == 'INPUT' && test_type == 'TEXT') || test_var == 'TEXTAREA'){ return e.keyCode; }else if (e.keyCode == 13){ <submit form> e.preventDefault(); } } }else{ document.onkeydown = function(){ var test_var=event.srcElement.tagName.toUpperCase(); if (event.srcElement.type) var test_type=event.srcElement.type.toUpperCase(); if ((test_var == 'INPUT' && test_type == 'TEXT') || test_var == 'TEXTAREA'){ return event.keyCode; }else if (event.keyCode == 13){ <submit value> event.returnValue=false; } } } Matthew Altuğ Bilgin Altıntaş wrote: > > Hi Martin; > > It works thanks; but my condition needs "onkeydown" anyway now i am > posting > the complete solution for others > > Code goal : user enters some char in textfield and press enter, and data > comes via ajax. > > final TextField<String> txtMy= new TextField<String>("txtMy", new > Model("")) > ; > txtMy.add(new AjaxFormComponentUpdatingBehavior("onkeydown") { > @Override > protected void onUpdate(AjaxRequestTarget target) { > //... > } > > @Override > protected IAjaxCallDecorator getAjaxCallDecorator() { > return new AjaxCallDecorator() { > private static final long serialVersionUID = 1L; > > @Override > public CharSequence decorateScript(CharSequence > script) > { > return "if(wicketKeyCode(event) == 13){" + script > + > " return false;}"; > } > }; > } > ; > }); > > Altug. > > 2010/10/19 Martin Grigorov <mgrigo...@apache.org> > >> 1. you need AjaxFormSubmitBehavior("onkeyup") >> 2. you'll have to add AjaxCallDecorator to it do fire only when the key >> is >> ENTER, i.e. event.keyCode === 13 >> >> 2010/10/19 Altuğ Bilgin Altıntaş <alt...@gmail.com> >> >> > Hi; >> > >> > How can i submit a form via Ajax when user hit the enter key on a >> TextField >> > ? >> > >> > I did below but it doesn't work. >> > >> > myTextField.add(new AjaxFormComponentUpdatingBehavior("onsubmit") { >> > @Override >> > protected void onUpdate(AjaxRequestTarget target) { >> > //... >> > >> > } >> > >> > }); >> > >> > Thanks. >> > >> > > -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/TextField-submit-via-Ajax-tp3002094p3264785.html Sent from the Users forum mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org