Peter
Peter

Reputation: 21

Add handler to list box for when user opens list box?

How do I add a handler to when a user just clicks on a list box but doesn't actually select anything? As far as I can tell, onclick on fires when the user selects an item in the dropdown and not when they actually click on it to see the options.

(Bonus points if you know how to do this in GWT instead of just raw javascript).

Thanks!

Upvotes: 2

Views: 2009

Answers (2)

Lam Chau
Lam Chau

Reputation: 841

You can use Event.addEventNativePreviewHandler() to preview the "click" event and do a event.stopPropagation() before the event bubbles up the ListBox (by checking the EventTarget).

On a related note, you can also check out ValueListBox which is in GWT 2.0+ which has a ValueChangeEvent -> onValueChange() handler (and wraps a ListBox).

Upvotes: 1

fernandohur
fernandohur

Reputation: 7144

mmm you could use this for the first click and whenever it is focused

    ListBox l;
    l.addFocusHandler(new FocusHandler() {

        @Override
        public void onFocus(FocusEvent event) {
            // TODO Auto-generated method stub

        }
    });

and you could use whenever the area that covers the list box is clicked

    l.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            //
            System.out.println("you clicked me!");
        }
    });

Upvotes: 1

Related Questions