SuggestBox and HasBlurHandlers

196 views
Skip to first unread message

bestey

unread,
Feb 9, 2010, 12:32:05 AM2/9/10
to Google Web Toolkit
Just wondering if there is an easy way to know when focus is lost from
a SuggestBox?
It doesn't implement HasFocusHandlers and HasBlurHandlers but it does
have HasFocus!
Any advice would be appreciated.

Thanks,
Brian

Thomas Broyer

unread,
Feb 9, 2010, 4:00:23 AM2/9/10
to Google Web Toolkit

Attach your handlers to the underlying TextBoxBase
(suggestBox.getTextBox().addBlurHandler(...)) as you're told to do in
the JavaDoc for the deprecated addFocusListener:
http://google-web-toolkit.googlecode.com/svn/javadoc/2.0/com/google/gwt/user/client/ui/SuggestBox.html#addFocusListener(com.google.gwt.user.client.ui.FocusListener)

Norm Deane

unread,
Nov 1, 2013, 12:45:09 PM11/1/13
to google-we...@googlegroups.com
Adding a FocusHandler to the TextBox isn't quite what I need. The TextBox will blur when the user arrows down into the suggestion display. When this occurs they really haven't left the SuggestBox yet as they're still navigating through the suggestions. I'd be more interested in a blur event that is fired only when they're no longer in the TextBox and also no longer in the SuggestionDisplay. Any ideas on how to pull that off? I've tried several ideas and have come close but in some cases I end up with the blur event being fired twice.

Thanks,

Norm

Patrick Tucker

unread,
Nov 2, 2013, 9:37:26 AM11/2/13
to google-we...@googlegroups.com
What are you actually trying to do? Maybe we can suggest an alternative to the FocusHandler.

Norm Deane

unread,
Nov 2, 2013, 9:52:32 AM11/2/13
to google-we...@googlegroups.com
We're using a SuggestBox as an in-place editor and need to know when they're blurred from the SuggestBox so we can fire validation and other logic. If we only listen for the blur on the TextBox we can end up firing this logic while they're in the SuggestionDisplay which is premature.

Thanks,

Norm
Message has been deleted

Patrick Tucker

unread,
Nov 3, 2013, 10:42:40 AM11/3/13
to google-we...@googlegroups.com
Wouldn't a ValueChangeHandler be more appropriate for firing validation?

jaga

unread,
Nov 3, 2013, 5:25:23 PM11/3/13
to google-we...@googlegroups.com
How about extending the popup interface SuggestDisplay? You can then handle the callbacks which get fired when the popup is hidden.

Norm Deane

unread,
Nov 4, 2013, 12:14:56 PM11/4/13
to google-we...@googlegroups.com
Yes we're seeing situations where it doesn't fire a ValueChangedEvent. If you type some characters, arrow down into the search results, then tab out of the field it selects that suggestion, sets the textbox value, but doesn't fire a ValueChangedEvent.

Norm Deane

unread,
Nov 4, 2013, 12:19:45 PM11/4/13
to google-we...@googlegroups.com
We're doing that. One solution that almost worked was to listen for both the onBlur from the textbox and the onClose from our SuggestionDisplay's PopupPanel. In the onBlur for the textbox we would look to see if the SuggestionDisplay's PopupPanel was still visible. If so we knew they could be in the process of selecting a suggestion. For some reason this didn't seem to work. Even when the SuggestionDisplay was clearly not visible it would think that it was.

Norm Deane

unread,
Nov 4, 2013, 2:06:09 PM11/4/13
to google-we...@googlegroups.com
I took the code out of our app and simplified it a bit for the purposes of troubleshooting. I've attached a zip file containing the Eclipse project and source. Any ideas on how to make this work would be greatly appreciated.

The main idea is to have a SuggestBoxEditor widget that is like a SuggestBox that remembers the last selected value (if one was selected) and can fire an event whenever the user leaves the widget - and by that I mean no longer in the textbox or navigating through the choices in the SuggestionDisplay.

Thanks,

Norm
SuggestEditorDemo.zip

Patrick Tucker

unread,
Nov 8, 2013, 8:14:15 PM11/8/13
to google-we...@googlegroups.com
You can listen to SelectionEvents, which fire when the user selects an item in the popup. If you want the user to be able to type in a value and not select an item I would also listen to ValueChangeEvents.
Reply all
Reply to author
Forward
0 new messages