1. #1
    Sencha User
    Join Date
    Mar 2012
    Posts
    28
    Answers
    2
    Vote Rating
    0
    alexgrimaldi is on a distinguished road

      0  

    Default Unanswered: selectfield default value

    Unanswered: selectfield default value


    How can I set a default value in a selectfield? Say that I need the 'Second Option' to be selected as default.

    Code:
    Ext.create('Ext.form.Panel',{
        fullscreen:true,    
        items:[{            
           xtype:'fieldset',            
           title:'Select',            
           items:[{
             xtype:'selectfield',                    
             label:'Choose one',                    
             options:[
                {text:'First Option',  value:'first'},
                {text:'Second Option', value:'second'},
                {text:'Third Option',  value:'third'}
              ]
            }
          ]
    }] });
    Many Thanks,
    Alex

  2. #2
    Sencha User
    Join Date
    Nov 2011
    Posts
    72
    Answers
    3
    Vote Rating
    2
    sephyroth69 is on a distinguished road

      0  

    Default


    I think it works like the select in html, you need to give a value to your select.
    So try adding " value:'second' " to your selectfield config.

  3. #3
    Sencha User
    Join Date
    Mar 2012
    Posts
    28
    Answers
    2
    Vote Rating
    0
    alexgrimaldi is on a distinguished road

      0  

    Default


    Thanks sephyroth. Unfortunaltelly it does not work for me

  4. #4
    Sencha User
    Join Date
    Feb 2012
    Posts
    67
    Answers
    3
    Vote Rating
    1
    Soenhay is on a distinguished road

      0  

    Default


    Somewhere in a function or event get a reference to the selectfield then use the setValue function by passing in one of the option values.

    This is how to change it after it has been created:

    Code:
    this.down('selectfield').setValue('second');

    so a more complete example ( untested ) would be:

    Code:
    var somePanel = Ext.create('Ext.form.Panel', {
        fullscreen: true,
        items: [
            {
                xtype: 'fieldset',
                title: 'Select',
                items: [
                    {
                        xtype: 'selectfield',
                        label: 'Choose one',
                        options: [
                            {text: 'First Option',  value: 'first'},
                            {text: 'Second Option', value: 'second'},
                            {text: 'Third Option',  value: 'third'}
                        ]
                    }
                ]
            }
        ]
    });
    
    somePanel.down('selectfield').setValue('second');

  5. #5
    Sencha User
    Join Date
    Nov 2011
    Posts
    72
    Answers
    3
    Vote Rating
    2
    sephyroth69 is on a distinguished road

      1  

    Default


    I just tested it and I confirm that you can set a default value as I said before :
    Code:
    {
        xtype:'fieldset',
        title:'Select',
        items:[
            {
             xtype:'selectfield',
             label:'Choose one',
             value:'third',
             options:[
                  {text:'First Option', value:'first'},
                  {text:'Second Option', value:'second'},
                  {text:'Third Option', value:'third'}
             ]
        }
    ]}

  6. #6
    Sencha User
    Join Date
    Feb 2012
    Posts
    67
    Answers
    3
    Vote Rating
    1
    Soenhay is on a distinguished road

      0  

    Default


    O I didn't realize you wanted to set it when creating it even though you said "default value"... lol... but ya same thing.

  7. #7
    Sencha User
    Join Date
    Feb 2012
    Posts
    67
    Answers
    3
    Vote Rating
    1
    Soenhay is on a distinguished road

      0  

    Default


    Note to self:
    Read the entire question before answering

  8. #8
    Sencha User
    Join Date
    Nov 2011
    Posts
    72
    Answers
    3
    Vote Rating
    2
    sephyroth69 is on a distinguished road

      0  

    Default


    Well yeah, I supposed that it was what you wanted as you asked for the way to the default value

  9. #9
    Sencha User
    Join Date
    Mar 2012
    Posts
    28
    Answers
    2
    Vote Rating
    0
    alexgrimaldi is on a distinguished road

      0  

    Default


    Thanks guys. There must be something funny going on in my app.

Thread Participants: 2

Tags for this Thread