PDA

View Full Version : combo tpl



raj_plays
2 Dec 2012, 11:28 PM
Hi,
My combo has an item that is non selectable.
To that item I need to apply a different class so that it looks disabled.
I tried this with tpl but the code below duplicates the item. See attachment.
Please help.


var typeCombo = new Ext.form.ComboBox({
allowBlank: false,
typeAhead: true,
triggerAction: 'all',
forceSelection: true,
store: new Ext.data.XmlStore({
url: 'CampaignService.asmx/getCampaignTypes',
record: 'Table',
fields: [{
name: 'id',
type: 'int'
}, {
name: 'name',
type: 'string'
}],
autoLoad: true
}),
mode: 'local',
displayField: 'name',
valueField: 'id',
listClass: 'x-combo-list-small',
style: {
float: 'left'
},
tpl: new Ext.XTemplate(
'<tpl for=".">',
'<tpl if="id == 0">',
'<div class="x-combo-list-item-banned-true">{name}</div>',
'</tpl>',
'<div class="x-combo-list-item">{name}</div>',
'</tpl>'),
listeners: {
beforeselect: function (combo1, record, index) {


if (record.get('id') == 0) return false;


return true;
}
}
});

willigogs
3 Dec 2012, 12:16 AM
Yes, this is bound to happen, since you only have an if statement around the disabled option, but then put out the normal option immediately after for all...

raj_plays
3 Dec 2012, 9:58 AM
Thank you, willigogs (http://www.sencha.com/forum/member.php?235243-willigogs).
I modified my code to


tpl: new Ext.XTemplate(
'<tpl for=".">',
'<tpl if="id == 0">',
'<div class="x-combo-list-item-banned-true">{name}</div>',
'</tpl>',
'<tpl if="id != 0">',
'<div class="x-combo-list-item">{name}</div>',
'</tpl>',
'</tpl>'
)


Is it true that there is no else or else-if in tpl?

raj_plays
3 Dec 2012, 11:44 PM
There is a problem with the code above.
If I select any item in the combo, the item above it gets selected.
If I remove the tpl config from the combo, this problem goes away.
Please help. I need tpl to work properly.