-
26 Oct 2011 12:45 AM #1
Answered: set current value from combox
Answered: set current value from combox
Hello everyone.
i want to edit object, and set a current value for combox.
Use this code:
panelform.down('form').getForm().setValues(current_data) - did not work (all other values is ok), andPHP Code:var metrocombox = Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Метро',
store: Ext.create('Ext.data.Store', {
model: 'EstateMetro',
autoLoad: true,
minChars: 1,
}),
listeners:{
select:{
fn:function(combo, value) {
Ext.get('mycategory-id').set({value: value[0].data.id})
} }, },
editable: false,
inputId: 'mycategory-id',
displayField: 'name',
valueField: 'id',
name: 'metro_id',
xtype:'combo',
allowBlank: false,
width: 720,
triggerAction:'all',
mode:'local',
});
metrocombox.setValue(1)
metrocombox.setValue(1) - not work, why ?
how to set current value for combox ?
-
Best Answer Posted by skirtle
Whoa! Hold your horses. You've gone off in totally the wrong direction.
I've just taken a look at the code you posted on pastebin. The reason that code doesn't work is because your fields don't match. In your store you've called the field value but in the combobox you've called the field id.
It's up to you which one you change but the name of the field listed in valueField must also be present in the store's fields. For example, if you change it to:
then it should work fine.Code:valueField: 'value'
You do not need to change your call to setValue(1), that was fine the way it was.
-
26 Oct 2011 2:09 AM #2
The value you attempt to set must correspond to a value in the valueField of a record in your store. Do you definitely has a record with the id of 1? Note that the field name is case-sensitive and the value type must match the type in the field (i.e. the record must contain the number 1, not the string '1').
-
26 Oct 2011 9:14 AM #3
nope

http://pastebin.com/BTkB7u0B
just have error message - This fields is requered.
i think problem somewhere in listeners.
-
26 Oct 2011 9:33 AM #4
get it.
i should make:
directioncombox.setValue({'value': 1, 'name': 'Аренду'})
thank you, i almost lost belive that setValue works as i need
-
26 Oct 2011 11:58 AM #5
but i have other question,
is it possible to override setValue function like this ?
give me error underfined function override.PHP Code:Ext.form.Combox.override({
setValue: function(val) {
value = this.store.findRecord('value', val);
i = this.calOverridden(value);
}
});
Can some one give me a link to docs where i can find true way to override function in extjs ?
thank you
-
26 Oct 2011 8:25 PM #6
Whoa! Hold your horses. You've gone off in totally the wrong direction.
I've just taken a look at the code you posted on pastebin. The reason that code doesn't work is because your fields don't match. In your store you've called the field value but in the combobox you've called the field id.
It's up to you which one you change but the name of the field listed in valueField must also be present in the store's fields. For example, if you change it to:
then it should work fine.Code:valueField: 'value'
You do not need to change your call to setValue(1), that was fine the way it was.
-
27 Oct 2011 4:31 AM #7
Yap!
and it's work perfectly without listeners!
thanks !


Reply With Quote