WelcomeTo
WelcomeTo

Reputation: 20571

GWT. Fire ChangeEvent on ListBox programmatically.

I want to programmatically fire ListBox's ChangeEvent. I found function, but dont understand what type of parameter i need to pass:

DomEvent.fireNativeEvent(NativeEvent - where???, listBox());

Upvotes: 17

Views: 12329

Answers (3)

user3132194
user3132194

Reputation: 2547

It is possible to fire event using JSNI:

public native void fireOnChange(String elementId)/*-{
    var element = $doc.getElementById(elementId);
    if ( element )
        element.onchange();
}-*/;

Upvotes: 0

Oleksandr_DJ
Oleksandr_DJ

Reputation: 1515

It is old question, but I want to share my solution, because it is only one that works for me(gwt.version= 2.6.1 and com.github.jdramaix gwtchosen version = 1.2.0)

public class ChosenListBoxNew extends ChosenListBox {
    public ChosenListBoxNew() {
    super();
    }

    public void fireUpdateEvent(){
    ensureChosenHandlers().fireEvent(new ChosenChangeEvent(this.getValue(), this.getSelectedIndex(), null));
    }
}

And you can fire update event by calling fireUpdateEvent() of new class:

moduleSelectionLst.setSelectedIndex(-1); //Update selected value
moduleSelectionLst.update(); //Update UI
moduleSelectionLst.fireUpdateEvent();  // Fire update event

Upvotes: 0

Strelok
Strelok

Reputation: 51441

You can fire a native ChangeEvent on a widget using:

DomEvent.fireNativeEvent(Document.get().createChangeEvent(), yourListBox);

Upvotes: 32

Related Questions