Reputation: 21
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
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
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