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.
> >
>

Reply via email to