PDA

View Full Version : [FIXED-279][3.0.x] Ext.Action and Ext.Toolbar.TextItem



anotherpit
29 Sep 2009, 4:43 AM
Ext.Component is designed to be able to accept Ext.Action object as argument for constructor. But Ext.Toolbar.TextItem is not able to do it proprely.

Example:


// Some automatically updatable action that displays time
var time = new Ext.Action({
text:(new Date()).format('d.m.Y H:i')
});
var T = Ext.Toolbar;
var toolbar = new T([
// Our action has no handler, so we prefer lightweight text item instead of button
new T.TextItem(time)
]);
// Toolbar is rendered empty


Fix (red to remove, green to add):

var T = Ext.Toolbar;
T.TextItem = Ext.extend(T.Item, {
constructor: function(config){
if (Ext.isString(config)) {
config = { text : config };
}
if (Ext.isString(config)) {
config = { autoEl: {cls: 'xtb-text', html: config }};
} else {
config.autoEl = {cls: 'xtb-text', html: config.text || ''};
}
T.TextItem.superclass.constructor.call(this, config);
},
onRender : function(ct, position) {
this.autoEl = {cls : 'xtb-text', html : this.initialConfig.text || ''};
T.TextItem.superclass.onRender.call(this, ct, position);
},

});

Condor
29 Sep 2009, 5:04 AM
Almost. IMHO it should be:

var T = Ext.Toolbar;
T.TextItem = Ext.extend(T.Item, {
constructor: function(config){
T.TextItem.superclass.constructor.call(this, Ext.isString(config) ? {text: config} : config);
},
onRender : function(ct, position) {
this.autoEl = {cls: 'xtb-text', html: this.text || ''};
T.TextItem.superclass.onRender.call(this, ct, position);
},

});
(removed reference to initialConfig and shortened the code a bit)

anotherpit
30 Sep 2009, 3:06 PM
While not fixed in ExtJS code, you can use the following patch (just put somewhere after ExtJS code):

Ext.override(Ext.Toolbar.TextItem, {
onRender : function(ct, position) {
this.autoEl = this.baseAction ? {cls: 'xtb-text', html: this.text || ''} : this.autoEl;
Ext.Toolbar.TextItem.superclass.onRender.call(this, ct, position);
}
});

evant
1 Oct 2009, 8:09 AM
Fix applied to svn in rev #5444 for patch release 3.0.3.