View Full Version : Combobox problem with auto select field from store

11 Aug 2010, 12:10 AM
Hi is this possible?
I put combo in formpanel, conected store, and everythng is working, but i have a problem in autoselecting field in combo from store.

my store if simple {"results":[{"ModulIme":"Top Administrator","ID":"0"},{"ModulIme":"Administrator","ID":"1"},{"ModulIme":"User","ID":"2"}],"success":"true"}

and how can i put combo that is autoselected on some value from store.

{"results":[{"ModulIme":"Top Administrator","ID":"0" selected:"1"},{"ModulIme":"Administrator","ID":"1"},{"ModulIme":"User","ID":"2"}],"success":"true"}

Thanks in advance.

11 Aug 2010, 6:04 AM
Hey intro,

There isn't a way to do that. You have to set the value on the Combo itself, by either providing a "value" configuration, or calling "setValue". When the store's data has loaded, the proper item in the combo list will be selected at that time.

Hope that helps.

11 Aug 2010, 6:55 AM
Thank you very very much,
I tryed to put in designer value but it show just Ext.StoreMgr.get('BazaModul').getAt(2).get('ModulName');,
please do you have any example with extjs designer.

11 Aug 2010, 7:00 AM
Hi i made that combo show data this.ModulCenter1.setValue("asdasd"); thats ok, but how can i check what data is selected from store..


11 Aug 2010, 9:18 AM
There is not a way to check a selection status of a Record in a Store, because the Store is completely disparate from the notion of "being selected". Only the ComboBox knows about this. With that said, if you need to check the store and *only* the store, you can have an additional field in the Store named "isSelected" or something thereof, and on the 'select' event of the ComboBox, you can update the Record's isSelected value to true, and set all other records to false. Or, you can maintain a publicly accessible variable that stores the ID of the selected record in the same 'select' event, and then can be compared to your records to find the selected one. Let me know if you need a quick code sample to accomplish that, I'd be happy to supply one.

11 Aug 2010, 9:44 AM
Hi, thanks for fast reply...
Ok i have one table : {"results":[{"ID":"6","ModulName":"Download" ,"selected":"false"},{"ID":"5","ModulName":"Newsletter" ,"selected":"true"},{"ID":"4","ModulName":"Anketa" ,"selected":"false"},{"ID":"3","ModulName":"Novosti" ,"selected":"false"},{"ID":"2","ModulName":"Galerija Fotografija" ,"selected":"false"},{"ID":"1","ModulName":"HTML" ,"selected":"false"}]}

and i have Store "BazaModul" - ID, ModulName,selected
xtype: 'combo',
fieldLabel: 'Drugi modul Centar',
anchor: '100%',
store: 'BazaModul',
hiddenValue: 'ID',
valueField: 'ModulName',
autoShow: true,
displayField: 'ModulName',
editable: false,
triggerAction: 'all',
forceSelection: true,
submitValue: true,
ref: '../../ModulNamecombo',
id: 'ModulNamecombo'

I hope that is ok.... yes please if you have quick code i think it will be helpful :)

Tanks in advance

11 Aug 2010, 10:16 AM
this part i think will be the best solution :
you can have an additional field in the Store named "isSelected" or something thereof, and on the 'select' event of the ComboBox, you can update the Record's isSelected value to true, and set all other records to false.
, i am working with extj designer


12 Aug 2010, 7:45 AM
var tree=this.Mytree;
var combo1=this.ModulNamecombo;
var centerform=this.FormCentar
function pregledizbornika() {
var id= tree.getSelectionModel().getSelectedNode().id;

// pregleda sadrzaja izbornik
url: 'izbornik_tree.php',
params: {
id: id,

failure: function(form, action) {
Ext.Msg.alert("Load failed", action.result.errorMessage);


combo1.setValue(centerform.ModulCentar1); this is my problem }

How can i set vaue from centerform.getForm().load to combo1.setValue

Thanks in advanceB)

12 Aug 2010, 11:32 AM
Hi intro,

I have no idea what "centerform.ModulCentar1" is...is it a field component? Or just a value you are setting?

How about this?

success: function(){
// assuming ModulCentar1 is a form field that is now populated from the load() call

Here is some code to help manage the record selection:

combo1.on('select', function(cmbx, record){
record.set('selected', true);
if (r.id != record.id){
r.set('selected', false);
}, this);
}, this);