You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Istvan De <su...@freemail.hu> on 2007/08/03 00:14:13 UTC

ListMultipleChoice and keypress

Hi!

How to receive a javascript keypress event from a ListMultipleChoice?

Basically I'd need to have a callback (on certain keys like enter, and 
arrow keys) with the currently selected items.

I've tried AjaxFormComponentUpdatingBehavior, I've got two problems with it:
- How to have this callback only on certain keys, not any key?
- When the arrow keys are used, the callback is called *before* the 
actual moving of the selection is done in the browser, so I cannot 
detect the newly selected item. (this is a JavaScript limitation afaik, 
but maybe this can be worked around by sending the currently selected 
item+the code of the pressed key)

Any ideas?

Best regards,
Istvan

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: ListMultipleChoice and keypress

Posted by Damian Mendez Romera <da...@teracode.com>.
You can use an AjaxFormComponentUpdatingBehavior("keyup") and override 
the getAjaxCallDecorator method.

Example:

myLMC.add(new AjaxFormComponentUpdatingBehavior("keyup") {
    onUpdate() {
       // your logic
    }

    getAjaxCallDecorator() {
       return new AjaxCallDecorator() {
          decorateScript(script) {
             return "if (pressedKey == 'K') { " + script + "}";
          }
       };
    }
});

Of course you will need a more complex JavaScript logic but this example 
only shows how to add a conditional callback to your ajax behavior :)

Istvan De wrote:
> Hi!
>
> How to receive a javascript keypress event from a ListMultipleChoice?
>
> Basically I'd need to have a callback (on certain keys like enter, and 
> arrow keys) with the currently selected items.
>
> I've tried AjaxFormComponentUpdatingBehavior, I've got two problems 
> with it:
> - How to have this callback only on certain keys, not any key?
> - When the arrow keys are used, the callback is called *before* the 
> actual moving of the selection is done in the browser, so I cannot 
> detect the newly selected item. (this is a JavaScript limitation 
> afaik, but maybe this can be worked around by sending the currently 
> selected item+the code of the pressed key)
>
> Any ideas?
>
> Best regards,
> Istvan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org