I have a dialog which has a listbox and two buttons. The listbox has
some listitems in it. And some of the items are disabled.
What I want is to disable the button when user choose the disabled
items in the list. I can do this by adding an event listener to each
of the listitem.
This line works fine:
listitem.addEventListener('click', listItemSelectListener, true);
But it only response to the mouse click event. In order to handle
keyboard selection (with up/down key), which event I should listen?
I've tried 'focus' and 'select' but neither of them worked for me.
Any idea?
Thanks a lot!
Calvin
> What I want is to disable the button when user choose the disabled items
> in the list.
That sounds strange, as in theory it shouldn't be possible for the user
to select disabled items.
> I can do this by adding an event listener to each of the
> listitem.
Note that you could instead add a single event listener to the listbox
and then get the listitem that triggered each event from
Event.originalTarget.
> This line works fine:
> listitem.addEventListener('click', listItemSelectListener, true);
>
> But it only response to the mouse click event. In order to handle
> keyboard selection (with up/down key), which event I should listen?
You should listen for the "command" event. See
XUL:Events#Common_XUL_events on MDC for more information:
http://developer.mozilla.org/en/docs/XUL:Events#Common_XUL_events
-myk
> In order to handle keyboard selection (with up/down key), which event
> I should listen?
>
> I've tried 'focus' and 'select' but neither of them worked for me.
> Any idea?
"select" should work, although note that this event is fired by the
listbox rather than any of its items.
--
Warning: May contain traces of nuts.
I shouldn't listener to the event of listitem itself. Listen to the
'select' event of listbox is good.
- Calvin
On 20-Dec-07, at 9:34 PM, Calvin Liu wrote:
> Hi, there,
>
> I have a dialog which has a listbox and two buttons. The listbox has
> some listitems in it. And some of the items are disabled.
> What I want is to disable the button when user choose the disabled
> items in the list. I can do this by adding an event listener to each
> of the listitem.
>
> This line works fine:
> listitem.addEventListener('click', listItemSelectListener, true);
>
> But it only response to the mouse click event. In order to handle
> keyboard selection (with up/down key), which event I should listen?
>
> I've tried 'focus' and 'select' but neither of them worked for me.
> Any idea?
>
> Thanks a lot!
> Calvin
> _______________________________________________
> dev-extensions mailing list
> dev-ext...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-extensions
>
>