Hi! In one of my projects, I did connect the combo boxes - country, region, city.
The problem is, when rendering ComboBox, is not always displayed parameter
displayField. Rather, instead of the name indicates id.
Code example:
..........
{
xtype: 'westh-hotels-country'
,fieldLabel: _('westh.country')
,description: MODx.expandHelp ? '' : _('westh.desc_country')
,name: 'country'
,id: 'westh-country-category' + config.record.id
,anchor: '100%'
,value: config.record.con_id || 0
,allowBlank: false
,forceSelection: true
,listeners: {
select: { fn:function(combo, value){
var acb = Ext.getCmp('westh-region-category' + config.record.id);
if (acb) {
var s = acb.store;
s.baseParams['country'] = value.id;
s.removeAll().load();
acb.clearValue();
}
var act = Ext.getCmp('westh-town-category' + config.record.id);
if (act) {
var t = act.store;
act.setDisabled(true);
act.clearValue();
}
}
}
}
},{
xtype: 'westh-hotels-region'
,fieldLabel: _('westh.region')
,description: MODx.expandHelp ? '' : _('westh.desc_region')
,name: 'region'
,id: 'westh-region-category' + config.record.id
,anchor: '100%'
,value: config.record.reg_id || 0
,allowBlank: false
,forceSelection: true
,listeners: {
select: { fn:function(combo, value){
var acr = Ext.getCmp('westh-town-category' + config.record.id);
if (acr) {
acr.setDisabled(false);
var r = acr.store;
r.baseParams['region'] = value.id;
r.removeAll().load();
acr.clearValue();
}
}
}
}
},{
xtype: 'westh-hotels-town'
,fieldLabel: _('westh.town')
,description: MODx.expandHelp ? '' : _('westh.desc_town')
,name: 'sity'
,id: 'westh-town-category' + config.record.id
,anchor: '100%'
,value: config.record.town_id || 0
,allowBlank: false
,forceSelection: true
}
........
.......
MODx.combo.country = function(config) {
config = config || {};
Ext.applyIf(config,{
name: 'country'
,hiddenName: 'country'
,displayField: 'title'
,valueField: 'id'
//,editable: true
,fields: ['title','id']
,pageSize: 20
//,value: config.record.con_id || ''
,emptyText: _('westh.country.no')
,url: Westh.config.connectorUrl
,baseParams: {
action: 'mgr/country/getList'
,'combo': true
}
});
MODx.combo.country.superclass.constructor.call(this,config);
};
Ext.extend(MODx.combo.country,MODx.combo.ComboBox);
Ext.reg('westh-hotels-country',MODx.combo.country);
MODx.combo.region = function(config) {
config = config || {};
Ext.applyIf(config,{
name: 'region'
,hiddenName: 'region'
,displayField: 'title'
,valueField: 'id'
//,editable: true
,fields: ['title','id']
,pageSize: 20
//,value: config.record.con_id || ''
,emptyText: _('westh.region.no')
,url: Westh.config.connectorUrl
,baseParams: {
action: 'mgr/region/getList'
,'combo': true
,'country': country_id
}
});
MODx.combo.region.superclass.constructor.call(this,config);
};
Ext.extend(MODx.combo.region,MODx.combo.ComboBox);
Ext.reg('westh-hotels-region',MODx.combo.region);
MODx.combo.town = function(config) {
config = config || {};
Ext.applyIf(config,{
name: 'town'
,hiddenName: 'town'
,displayField: 'title'
,valueField: 'id'
//,editable: true
,fields: ['title','id']
,pageSize: 20
,tpl: new Ext.XTemplate('<tpl for="."><div class="x-combo-list-item">{title} ({id})</div></tpl>')
//,value: config.record.con_id || ''
,emptyText: _('westh.town.no')
,url: Westh.config.connectorUrl
,baseParams: {
action: 'mgr/town/getList'
,'combo': true
,'region': region_id
}
});
MODx.combo.town.superclass.constructor.call(this,config);
};
Ext.extend(MODx.combo.town,MODx.combo.ComboBox);
Ext.reg('westh-hotels-town',MODx.combo.town);
To understand it,
watch the video
How to make the display name instead of id?
Thanks in advance!
[ed. note: valikras last edited this post 14 years, 1 month ago.]