Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT input event on TextBox

Tags:

gwt

Given the following code:

    TextBox tb = new TextBox();
    tb.addValueChangeHandler(new ValueChangeHandler<String>() {

        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            Window.alert(event.getValue());

        }
    });

onValueChange will be called if the TextBox loses focus. I am trying to have it called whenever the input value changes. The solutions I have read all involve handling the keyup and paste events such as in this answer. How to build a Facebook-style input box in GWT Hasn't this been addresses in GWT 2.5.1? Is there a way to bind to the native input change method? Another widget or using the UI framework would be acceptable if they have this functionality

like image 772
Nathaniel Johnson Avatar asked Oct 05 '13 18:10

Nathaniel Johnson


2 Answers

The only way in GWT is to bind to the key down/key up and paste events.

Please send a patch to add support for the input event (using addBitlessDomHandler): http://www.gwtproject.org/makinggwtbetter.html, it should be rather easy (add a acase in DOMImpl) and has good chances to make it in (and if sent early enough, would have good chances to ship in GWT 2.6)

like image 50
Thomas Broyer Avatar answered Sep 21 '22 02:09

Thomas Broyer


The solution is use the right event and that is the input event, so look how to hook on it, there are many ways to do it. Because I work with elements and not with Widgets this the code that I use it:

    Element input = Document.get().getElementById("my-input");
    DOM.sinkBitlessEvent(input, "input");
    DOM.setEventListener(input, event -> GWT.log("Event!"));
like image 40
Daniel De León Avatar answered Sep 23 '22 02:09

Daniel De León