Search code examples
gwtgxt

GXT ComboBox unselect after selection


I have a GXT ComboBox which is bound to a ListStore and has a addSelectionHandler that is called which is working fine. I have also used the combo.setEmptyText("Select an item..").

But, when the user makes a selection I'd like to have the ComboBox return to its' "no selection" state. How can I have it return to show the "Select an item.."?

StProperties props = GWT.create(StProperties.class);
ListStore<St> sts = new ListStore<St>(combo.id());

combo = new ComboBox<St>(sts, props.name());
combo.setTypeAhead(true);
combo.setTriggerAction(TriggerAction.ALL);
addHandlersForEventObservation(combo,props.name());
...


combo.addSelectionHandler(new SelectionHandler<T>() {

    public void onSelection(SelectionEvent<T> event) {
        System.out.println("value selected:"+event.getSelectedItem());
        // handle selection
        // unselect item in combo here ---
  }

});

Solution

  • It appears there is presently a bug in GXT 3 around this issue, as reported at http://www.sencha.com/forum/showthread.php?234736, present as of GXT 3.0.4. As reported in that bug, it seems that you can call first setValue(null), followed by redraw(true) then setText(null) on the field.

    This also happens to a few other fields - based on the details of the report it seems probable that the bug is in TriggerField itself, so this workaround may be required for all subclasses.