Results 1 to 2 of 2

Thread: ComboBox GXT 3.1.4. empty value

  1. #1
    Sencha Premium Member
    Join Date
    Feb 2016
    Posts
    1

    Default ComboBox GXT 3.1.4. empty value

    ComboBox(GXT 3.1.4): add empty value to drop-down when 'allow blank' is true

    Right now, once I select a value from a drop down list, I'm not able to remove it. Can you add a blank option when 'allow blank' option is set to true?

  2. #2
    Sencha Sr Product Manager
    Join Date
    Jan 2012
    Location
    Arlington, WA
    Posts
    1,178

    Default

    There is a feature request to add a empty value option.

    In the meantime it has to be controlled with the model. Something like this:
    Code:
        combo.getStore().add(new Company("-1", ""));
        combo.getStore().add(new Company("1", "2011"));
        combo.getStore().add(new Company("2", "2012"));
        combo.getStore().add(new Company("3", "2013"));
        combo.getStore().add(new Company("4", "2014"));
        combo.getStore().add(new Company("5", "2015"));
    Code:
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.user.client.ui.RootPanel;
    import com.sencha.gxt.cell.core.client.form.ComboBoxCell.TriggerAction;
    import com.sencha.gxt.data.shared.LabelProvider;
    import com.sencha.gxt.data.shared.ListStore;
    import com.sencha.gxt.data.shared.ModelKeyProvider;
    import com.sencha.gxt.widget.core.client.event.CollapseEvent;
    import com.sencha.gxt.widget.core.client.event.CollapseEvent.CollapseHandler;
    import com.sencha.gxt.widget.core.client.form.ComboBox;
    
    
    public class ComboboxTest2 implements EntryPoint {
    
    
      private ComboBox<Company> combo;
    
    
      @Override
      public void onModuleLoad() {
        ListStore<Company> store = new ListStore<Company>(new ModelKeyProvider<Company>() {
          @Override
          public String getKey(Company item) {
            return item.getId();
          }
        });
    
    
        LabelProvider<Company> labelProvider = new LabelProvider<Company>() {
          @Override
          public String getLabel(Company item) {
            return item.getName();
          }
        };
    
    
        combo = new ComboBox<Company>(store, labelProvider);
        combo.setForceSelection(true);
        combo.setTypeAhead(true);
        combo.setTriggerAction(TriggerAction.ALL);
        combo.setTypeAheadDelay(0);
        combo.setValue(new Company("2", "2012"));
        //combo.setEditable(false);
        combo.setSelectOnFocus(true);
    
    
        // Optional, to commit value
        combo.addCollapseHandler(new CollapseHandler() {
          @Override
          public void onCollapse(CollapseEvent event) {
            combo.finishEditing();
          }
        });
    
    
        combo.getStore().add(new Company("-1", ""));
        combo.getStore().add(new Company("1", "2011"));
        combo.getStore().add(new Company("2", "2012"));
        combo.getStore().add(new Company("3", "2013"));
        combo.getStore().add(new Company("4", "2014"));
        combo.getStore().add(new Company("5", "2015"));
    
    
        RootPanel.get().add(combo, 100, 100);
      }
    
    
      public class Company {
        private String id;
        private String name;
    
    
        public Company(String id, String name) {
          this.id = id;
          this.name = name;
        }
    
    
        public String getId() {
          return id;
        }
    
    
        public String getName() {
          return name;
        }
    
    
        @Override
        public String toString() {
          String s = "";
          s += "id=" + id + ",";
          s += "name=" + name;
          return s;
        }
      }
    
    
    }
    Does that help?

Similar Threads

  1. Replies: 1
    Last Post: 30 Jul 2014, 3:38 AM
  2. add empty value to combobox ?
    By dedoz in forum Ext: Q&A
    Replies: 2
    Last Post: 28 Mar 2012, 9:49 AM
  3. Combobox empty value
    By Qarea in forum Sencha Ext JS Q&A
    Replies: 1
    Last Post: 8 Mar 2012, 2:48 PM
  4. Replies: 2
    Last Post: 22 Oct 2011, 9:45 AM
  5. ComboBox with empty row
    By kaushikGXT in forum Sencha GXT Q&A
    Replies: 1
    Last Post: 18 Dec 2009, 4:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •