-
5 Apr 2012 6:35 AM #1
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.
Many Thanks,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'} ] } ] }] });
Alex
-
5 Apr 2012 6:41 AM #2
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.
-
5 Apr 2012 6:46 AM #3
Thanks sephyroth. Unfortunaltelly it does not work for me
-
5 Apr 2012 7:06 AM #4
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 Apr 2012 7:12 AM #5
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'} ] } ]}
-
5 Apr 2012 7:15 AM #6
O I didn't realize you wanted to set it when creating it even though you said "default value"... lol... but ya same thing.
-
5 Apr 2012 7:20 AM #7
Note to self:
Read the entire question before answering
-
5 Apr 2012 7:21 AM #8
Well yeah, I supposed that it was what you wanted as you asked for the way to the default value

-
5 Apr 2012 8:08 AM #9
Thanks guys. There must be something funny going on in my app.


Reply With Quote