Thanks for this great idea! I find it very useful.
Here is the code which works for me on Ext 2.2 with id/value combo:
Code:
var flatCategoriesStore = new Ext.data.Store
({
// load using HTTP
proxy: new Ext.data.HttpProxy
({
url: 'categories/flat',
method: 'GET'
}),
reader: new Ext.data.JsonReader
({
root: 'items',
totalProperty: 'count',
id: 'id',
fields: [
{name: 'id', type: 'int'},
{name: 'name', type: 'string'}
]
})
});
var comboAlias = new Ext.form.ComboBox
({
store: flatCategoriesStore,
displayField: 'name',
valueField: 'id',
hiddenName: 'alias',
fieldLabel: Lang.Alias,
allowBlank: true,
editable: false,
shadow: false,
anchor: '100%',
mode: 'local',
triggerAction: 'all',
maxHeight: 200,
emptyText: Lang.None,
tpl: '<tpl for="."><div><div id="treeAddAlias"></div></div></tpl>',
selectedClass: '',
onSelect: Ext.emptyFn,
renderer:
function(data)
{
record = flatCategoriesStore.getById(data);
if(record)
{
return record.data.name;
}
else
{
return data;
}
},
tooltipText: Lang.AliasTip,
listeners:
{
render: CMS.setFormFieldTooltip
}
});
var treeAlias = new Ext.tree.TreePanel
({
loader: new Ext.tree.TreeLoader({dataUrl: 'categories/combo'}),
root: new Ext.tree.AsyncTreeNode(),
rootVisible: false,
lines: false,
autoScroll: true,
border: false,
height: 200,
enableDD: false,
useArrows: true,
listeners:
{
click: function(node)
{
comboAlias.setValue(node.attributes.cid);
comboAlias.collapse();
}
}
});
comboAlias.on('expand', function()
{
treeAlias.render('treeAddAlias');
});
flatCategoriesStore.on('load', function()
{
comboAlias.setValue(category.attributes.alias);
});
flatCategoriesStore.load();
