1. #1
    Sencha User
    Join Date
    Jun 2012
    Posts
    25
    Vote Rating
    0
    Answers
    1
    DmitryF is on a distinguished road

      0  

    Default Answered: Add blank entry to combobox

    Answered: Add blank entry to combobox


    Hello.
    I have a combobox with data.Store.
    How i can add an empty option to the combobox?

  2. A simple solution might be to use the combo's emptyText config option.

    If that doesn't work for you, you could always use the store's load event to insert a blank record..

  3. #2
    Sencha - Community Support Team friend's Avatar
    Join Date
    Apr 2011
    Posts
    895
    Vote Rating
    27
    Answers
    106
    friend has a spectacular aura about friend has a spectacular aura about

      0  

    Default


    A simple solution might be to use the combo's emptyText config option.

    If that doesn't work for you, you could always use the store's load event to insert a blank record..
    Last edited by friend; 6 Jul 2012 at 8:47 AM. Reason: clarity

  4. #3
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,197
    Vote Rating
    482
    Answers
    690
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      1  

    Default


    Something like this should work:

    Code:
    // The data store containing the list of states
    var states = Ext.create('Ext.data.Store', {
        fields: ['abbr', 'name'],
        data : [
            {"abbr":"AL", "name":"Alabama"},
            {"abbr":"AK", "name":"Alaska"},
            {"abbr":"AZ", "name":"Arizona"}
        ],
        
        listeners: {
            load: function(store){
                var rec = { abbr: '', name: '-' };
                store.insert(0,rec);    
            }
        }
    
        
    });
    
    // Create the combo box, attached to the states data store
    Ext.create('Ext.form.ComboBox', {
        fieldLabel: 'Choose State',
        store: states,
        queryMode: 'local',
        displayField: 'name',
        valueField: 'abbr',
        renderTo: Ext.getBody()
    });
    Scott.

  5. #4
    Sencha User
    Join Date
    Jun 2012
    Posts
    25
    Vote Rating
    0
    Answers
    1
    DmitryF is on a distinguished road

      0  

    Default


    Thank you! It works great.

    Code:
    Ext.define('AM.store.Beers', {
        extend: 'Ext.data.Store',
        model: 'AM.model.Beer',
    
    
        listeners: {
            load: function(store) {
                var model = Ext.create('AM.model.Beer', {
                    id: '',
                    number: 'Not Set'
                });
                store.autoSync = false;
                store.insert(0,model);
            }
        }
    });

  6. #5
    Sencha User
    Join Date
    Nov 2012
    Location
    INDIA, Hyderabad
    Posts
    23
    Vote Rating
    0
    Answers
    2
    ravimaroju is on a distinguished road

      0  

    Default


    Great Work.. Its Working Absolutely fine
    Ravi Maroju

  7. #6
    Sencha User
    Join Date
    May 2013
    Location
    Hyderabad, India
    Posts
    16
    Vote Rating
    1
    Answers
    1
    hmnth1 is on a distinguished road

      0  

    Default


    How can i set a default value in selected state?