PDA

View Full Version : [FIXED] How to initialize a select field - value does not work



cyberwombat
14 Nov 2011, 1:27 PM
Why does this not work?



{
xtype: 'selectfield',
options: [
{text: 'First Option', value: 'first'},
{text: 'Second Option', value: 'second'},
{text: 'Third Option', value: 'third'}
],
value: 'second',
}


This does not set the second option - it defaults to first. value seems to work fine for text fields.

mitchellsimoens
16 Nov 2011, 1:52 PM
It looks to be a bug as in the source of Select it seems to set the value to the first record:


updateOptions: function(newOptions) {
var store = this.getStore(),
record;

if (!newOptions) {
store.clearData();
this.setValue(null);
}
else {
store.loadData(newOptions);

record = store.getAt(0);
this.setValue(record);
}
},

It could be:


updateOptions: function(newOptions) {
var store = this.getStore(),
record;

if (!newOptions) {
store.clearData();
this.setValue(null);
}
else {
store.loadData(newOptions);

if (!this.record) {
record = store.getAt(0);
this.setValue(record);
}
}
},

or


updateOptions: function(newOptions) {
var store = this.getStore(),
record;

if (!newOptions) {
store.clearData();
this.setValue(null);
}
else {
store.loadData(newOptions);

record = this.record || store.getAt(0);
this.setValue(record);
}
},

May need to do a check to see if this.record is present in the store after the loadData. If it is then use that if not then do the store.getAt(0).

cyberwombat
16 Nov 2011, 2:04 PM
Ok. I assume I don't have to file this as a bug then as you prob have that handled. Thanks

mitchellsimoens
16 Nov 2011, 2:08 PM
Ok. I assume I don't have to file this as a bug then as you prob have that handled. Thanks

I will move it over. I gave you the code suggestions to help you create an override to fix it (test it first).

mishoboss
16 Dec 2011, 7:31 AM
It seems that this bug is presented in the toggle and slide fields too. I can't initialize them with a value attribute.

lylepratt
12 Jan 2012, 6:57 PM
This still doesn't seem to work in PR3.

Jamie Avins
13 Jan 2012, 9:12 AM
I'll reopen this to verify it.

ASraniel
29 May 2012, 5:28 AM
This is still a problem with version 2.0.1

Syntona
11 Jun 2012, 4:55 AM
this is working fine with me.


var SelectField = new Ext.form.Select({
xtype: 'selectfield',
id: 'YearFilter',
name: 'Options',
cls: 'x-select-dropdwn',
options: [
{ text: '2011', value: '2011' },
{ text: '2012', value: '2012' },
{ text: '2013', value: '2013' }
],
listeners: {
change: function (selectField, value) {
console.log('Selected ' + value);
}
}
});

SelectField.setValue('2012');