Hybrid View

  1. #1
    Ext GWT Premium Member
    Join Date
    Jan 2010
    Posts
    29
    Vote Rating
    0
    shawnjohnson is on a distinguished road

      0  

    Default 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);
            
          }  
    }

  2. #2
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    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.

  3. #3
    Ext GWT Premium Member
    Join Date
    Jan 2010
    Posts
    29
    Vote Rating
    0
    shawnjohnson is on a distinguished road

      0  

    Default


    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.

  4. #4
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    We are overriding getValue - based on your recommendation in another thread, but that was a different question I was asking.
    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.

    Is it working as you want without this override?

  5. #5
    Ext GWT Premium Member
    Join Date
    Jan 2010
    Posts
    29
    Vote Rating
    0
    shawnjohnson is on a distinguished road

      0  

    Default


    Sorry for the late reply - Yes, removing the override of getValue resolved the typeAhead issue. Thanks!

Similar Threads

  1. Ext 2.2 Combobox TypeAhead
    By stratboogie in forum Community Discussion
    Replies: 2
    Last Post: 8 Sep 2010, 10:08 AM
  2. Replies: 10
    Last Post: 2 Sep 2009, 10:44 AM
  3. ComboBox with TypeAhead - can someone help me?
    By Cypher in forum Ext GWT: Help & Discussion (1.x)
    Replies: 2
    Last Post: 13 Aug 2009, 8:25 PM
  4. ComboBox typeAhead
    By Tony Mariella in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 13 May 2008, 6:58 AM

Thread Participants: 1

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi