Hello I have the next problem, I want to render the html of my display value in a combobox, at the moment I load a store with the html ready, it renders the html when I show
This require few steps. Problem is that ComboBox
has input field underneath, and inputs can't display html. So first step is to change template which replace input with div. Eg:
fieldSubTpl: [
'<div class="{hiddenDataCls}" role="presentation"></div>',
'<div id="{id}" type="{type}" ',
'<tpl if="size">size="{size}" </tpl>',
'<tpl if="tabIdx">tabIndex="{tabIdx}" </tpl>',
'class="{fieldCls} {typeCls}" autocomplete="off"></div>',
'<div id="{cmpId}-triggerWrap" class="{triggerWrapCls}" role="presentation">',
'{triggerEl}',
'<div class="{clearCls}" role="presentation"></div>',
'</div>',
{
compiled: true,
disableFormats: true
}
]
Then change template which shows selected value:
displayTpl: Ext.create('Ext.XTemplate', [
'<tpl for=".">',
'<img src="http://phpbb3.pl/adm/images/icon_edit.gif" />',
'{[typeof values === "string" ? values : values["title"]]}',
'</tpl>'
])
Another thing is to create new list-item template. Eg:
listConfig: {
getInnerTpl: function() {
return '<div class="search-item">' +
'<h3><img src="http://phpbb3.pl/adm/images/icon_edit.gif" /><span>{[Ext.Date.format(values.lastPost, "M j, Y")]}<br />by {author}</span>{title}</h3>' +
'{excerpt}' +
'</div>';
}
}
And the last thing - you must ensure that the value is setted correctly into div. For that you should override setRawValue
method:
setRawValue: function(value) {
var me = this;
value = Ext.value(value, '');
me.rawValue = value;
// Some Field subclasses may not render an inputEl
if (me.inputEl) {
// me.inputEl.dom.value = value;
// use innerHTML
me.inputEl.dom.innerHTML = value;
}
return value;
}
Notice that new template doesn't contain any input
field, so value will not be submited. If you need use such combo with form, you should add hidden input somewhere in fieldSubTpl
and set value for it in setRawValue
.
Working sample: http://jsfiddle.net/lolo/8Xs5h/1/
We have similar task to display selected color. Our solution is overriding of combobox template:
var store = new Ext.data.SimpleStore({
fields: ['num','id', 'color']
});
var tplColor = new Ext.XTemplate(
'<tpl for="."><div id = "seriesColor_{num}" class="combo-result-item">',
'<div class="combo-texture" style="background-color:{color};"> </div>',
'</div></tpl>'
);
new Ext.form.ComboBox({
tpl: tplColor,
store: store,
...
};
You can do something similar but use image instead of background-color.