ComboBox with Typeahead, but not editable?
I'm trying to add a ComboBox - set the store, and allow type-ahead, without allowing the user to enter new values. It appears that I can only have type-ahead when readonly=false and editable=true. However, editable=true seems to allow users to enter a new item into the combo box.
We had this working in GXT 1.5, but the 2.x seems to be working a little different?
Code:
public class MyTestEntryPoint implements EntryPoint {
public void onModuleLoad() {
VerticalPanel vp = new VerticalPanel();
vp.setSpacing(10);
createColumnForm(vp);
RootPanel.get().add(vp);
}
private void createColumnForm(VerticalPanel vp) {
FormPanel panel = new FormPanel();
List<Stock> stocks = TestData.getStocks();
Collections.sort(stocks, new Comparator<Stock>() {
public int compare(Stock arg0, Stock arg1) {
return arg0.getName().compareTo(arg1.getName());
}
});
ListStore<Stock> store = new ListStore<Stock>();
store.add(stocks);
final ComboBox<Stock> combo = new ComboBox<Stock>(){
@Override
public Stock getValue() {
Stock returnVal = super.getValue();
if(returnVal==null) {
Stock newStock = new Stock();
newStock.set( "name", getRawValue() );
newStock.set( "symbol", getRawValue() );
returnVal = newStock;
}
return returnVal;
}
};
combo.setName( "name" );
combo.setFieldLabel("Company");
combo.setDisplayField("name");
combo.setTriggerAction(TriggerAction.ALL);
combo.setStore(store);
combo.setAllowBlank( false );
combo.setEditable( false );
combo.setEmptyText( "Please choose a stock" );
combo.setForceSelection( true );
panel.add(combo);
Button submitButton = new Button( "Submit" );
FormButtonBinding buttonBinding = new FormButtonBinding( panel );
buttonBinding.addButton( submitButton );
panel.add( submitButton );
vp.add(panel);
}
}