-
28 Oct 2010 2:05 PM #1
ComboBox with Typeahead, but not editable?
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); } }
-
28 Oct 2010 2:37 PM #2
Your getValue override brakes it. You also need to remove the combo.setEditable( false ); call. Why are you overridng getValue?
I understood your text that you dont want to let the user enter new data. But your override simple allows this. It simple allows the value the user entered.
-
28 Oct 2010 6:03 PM #3
Thanks Sven, this seems to be working as expected.
We are overriding getValue - based on your recommendation in another thread, but that was a different question I was asking.
We were trying to dynamically build a form, some combo's change based on another value. In one case the Country will fill a State box only for certain countries. If the size of the store is 0, then I set my box to editable and allow users to enter a value - as if it were a checkbox. Though, early testing has gotten complaints that it looks like a combo instead of a text box. So, I guess in light of the issue overriding getValue, I may have to swap the combo box out for a text box.
-
29 Oct 2010 2:45 AM #4
This overrides allows the combo to return a real object if the entered value of the user was not found. So it is doing exactly what you dont want according to your description.We are overriding getValue - based on your recommendation in another thread, but that was a different question I was asking.
Is it working as you want without this override?
-
1 Nov 2010 3:15 PM #5
Sorry for the late reply - Yes, removing the override of getValue resolved the typeAhead issue. Thanks!
Similar Threads
-
Ext 2.2 Combobox TypeAhead
By stratboogie in forum Community DiscussionReplies: 2Last Post: 8 Sep 2010, 10:08 AM -
[1.0b1] EditorGrid ComboBox / ComboBox typeAhead anomaly
By mystix in forum Ext 1.x: BugsReplies: 10Last Post: 2 Sep 2009, 10:44 AM -
ComboBox with TypeAhead - can someone help me?
By Cypher in forum Ext GWT: Help & Discussion (1.x)Replies: 2Last Post: 13 Aug 2009, 8:25 PM -
ComboBox typeAhead
By Tony Mariella in forum Ext 2.x: Help & DiscussionReplies: 1Last Post: 13 May 2008, 6:58 AM


Reply With Quote