PDA

View Full Version : Click on label



wki01
17 Sep 2009, 7:37 AM
Instead of a button I would use only the label.
how to do so when I click on the label is handled the event?

thanks

My code:


var groupActions = new Ext.Panel({
frame : true,
title : 'Task Grouping',
collapsible : true,
items : [{
xtype : "label", // <--- NO WORK
text : "New",
iconCls : "icon-new16",
handler : function() {
alert("OK")
}
},{
xtype : "button", // <--- WORK
iconCls : "icon-new16",
text : "New",
handler : function() {
alert("OK")
}
}],
titleCollapse : true
});

Condor
17 Sep 2009, 7:43 AM
Ext.form.Label doesn't have a 'handler' config option and it also doesn't have a 'click' event. It also doesn't have an 'iconCls' config option.

So you're stuck with using:

{
xtype : "label",
text : "New",
cls : "icon-new16",
listeners : {
render : function(c) {
c.getEl().on('click', function() {
alert("OK");
});
}
}
}

ps. Instead of 'label' you could also use:

{
xtype: 'box',
autoEl: {cn: 'New'},
...
}
(uses a <div> instead of a <label>, which is usually preferred)