سؤال

I've been searching and searching and can't find a usable example of selecting all text within a GWT SuggestBox widget on focus. I understand you have to attach a focusListener to the widget, but then what? Can someone provide a working example of this?

هل كانت مفيدة؟

المحلول

Since every example I'd found online was using deprecated code (addFocusListener method), I ended up figuring this one out using the addFocusHandler method instead.

Here's how it was done:

    mySuggestBox.getTextBox().addFocusHandler(new FocusHandler() {
        @Override
        public void onFocus(FocusEvent event) {
            mySuggestBox.getTextBox().selectAll();
        }
    });

نصائح أخرى

I simply applied "addFocusListener" to the "TextBox" inside the SuggestBox in the creation of the SuggestBox (where the TextBox itself is reachable as you need it for the creation of the SuggestBox). I guess that in a way it's more logical this way.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top