PDA

View Full Version : Using template with Ext.form.Checkbox



VladSun
11 Mar 2011, 7:17 AM
Hello!
I want to apply a custom template for rendering the Checkbox label (i.e. the boxLabel). I can see that the "tpl" config option exists (together with the "data" and "tplWriteMode"), but setting them doesn't affect the Checkbox rendering. What's wrong? Here is the code (it's Radio, but it doesn't matter):


var radioBoxTemplate = new Ext.XTemplate
(
'<tpl for=".">',
'<div class="layout-radiobox-template">',
' <div class="layout-radiobox-template-name">{name}</div>',
' <div class="layout-radiobox-template-img"><img src="/images/layouts/{img}" /></div>',
' <div class="layout-radiobox-template-desc">{desc}"</div>',
'</div>',
'</tpl>'
);

var cbg = new Ext.form.RadioGroup(
{
columns : 1,
items :
[
{
name : 'a',
data :
{
name : 'name1',
img : 'img1',
desc : 'desc1'
},
tpl : radioBoxTemplate
},
{
name : 'a',
data :
{
name : 'name2',
img : 'img2',
desc : 'desc2'
},
tpl : radioBoxTemplate
}
]
});

Thank you!

PS: How to enable syntax highlighting?

steffenk
11 Mar 2011, 8:25 AM
there is no property tpl for radiogroup/checkbox group!

VladSun
12 Mar 2011, 6:32 AM
First, according to the ExtJS 3.3 API Docs, there IS a tpl and related config options (defined in Component superclass).
Second, I am NOT using the tpl config option for Checkbox/RadioGroup, but for the *items* config option - i.e. I am using the tpl config option for Checkbox/Radio components (and not Groups).

I can see from the source, that going up the prototype chain, finally the Ext.Component.render() is called ( Ext.form.Field and Ext.formCheckbox do not override it ) and it contains the code for rendering the component with a template defined:


if (this.tpl) {
if (!this.tpl.compile) {
this.tpl = new Ext.XTemplate(this.tpl);
}
if (this.data) {
this.tpl[this.tplWriteMode](contentTarget, this.data);
delete this.data;
}
}
So, I expect the template to be rendered somehow (even "wrong"), but nothing happens.

I've added some debugging lines:

if (this.tpl) {
console.log('Tpl exist')
if (!this.tpl.compile) {
this.tpl = new Ext.XTemplate(this.tpl);
}
if (this.data) {
console.log('data exist')
this.tpl[this.tplWriteMode](contentTarget, this.data);
delete this.data;
console.dir(contentTarget)
}
}
And everything seems fine - the two log lines exist, and the ids of the components are properly set.

VladSun
14 Mar 2011, 3:47 AM
Anyone?

Joe Kuan
21 Mar 2011, 7:27 AM
I try to put a image label next to a checkbox using Template but can't get it to work either.

Can anyone help?

Thanks in advance
Joe