PDA

View Full Version : [CLOSED]xtypes



tobiu
17 Feb 2011, 8:24 AM
hi team,

since this came up a couple of times, now would be a perfect time to clean this up.

it would be awesome, if you also could enter the full classname into that config like:



xtype : 'Ext.form.ComboBox'


otherwise we have to remember all existing xtypes, which are not always consistent.
a good example:

combo
numberfield


best regards
tobiu

steffenk
17 Feb 2011, 9:04 AM
i have to second this, i use this kind of xtype in all my components, easy to remember: the classname.

Francis_Lessard
17 Feb 2011, 9:14 AM
approve this
Francis !

iesdeveloper
17 Feb 2011, 9:21 AM
Actually that would be perfect...

Make xtype === class name

One less thing to document/remember.

nick_p
17 Feb 2011, 12:46 PM
The API docs will include the xtype next to the class name in the next release

alexbrina
17 Feb 2011, 1:25 PM
There was a recommendation for not using this kind of xtype, but I've been using this for a long time and not facing any problems

mschwartz
17 Feb 2011, 1:59 PM
Actually that would be perfect...

Make xtype === class name

One less thing to document/remember.



{
xtype: Ext.form.ComboBox,
// Combo config options:
store: ...
...
}

alexbrina
17 Feb 2011, 3:50 PM
This code make it possible right now. Would be easier if "types" var weren't private in Ext.ComponentMgr



Ext.onReady(function() {

Function.prototype.createSmartInterceptor = function(fcn, scope) {
var method = this;
return !Ext.isFunction(fcn) ?
this :
function() {
var me = this,
args = arguments;
fcn.target = me;
fcn.method = method;
/* original code
return (fcn.apply(scope || me || window, args) !== false) ?
method.apply(me || window, args) :
null;
*/
// new code allows changing function args
var result = fcn.apply(scope || me || window, args);
if (result === false) return null;
if (Ext.isArray(result)) args = result;
return method.apply(me || window, args);
};
};

Ext.ComponentMgr.create = Ext.ComponentMgr.create.createSmartInterceptor(
function(config, defaultType) {
if (config.xtype && Ext.isFunction(config.xtype)) {
config = new config.xtype(config);
return [config, defaultType];
}
}
);

Ext.create = Ext.ComponentMgr.create;

(new Ext.Window({
height:300,
width:400,
padding:5,
items:[{
// xtype:'textfield',
xtype:Ext.form.TextField,
value:'Testing...'
}]
})).show();

});

tobiu
17 Feb 2011, 3:56 PM
hmm, i still would prefer



xtype : 'Ext.form.TextField'


if i got it right, the new dependency loading system is build on using strings, so you don't get in danger to use classes that are not available yet.


best regards
tobiu

alexbrina
17 Feb 2011, 4:01 PM
Agree! Just a proof of concept. Anyway, with strings it's already possible. Try:



// just a matter of registering every component like this
Ext.reg('Ext.form.TextField', Ext.form.TextField);

var win = new Ext.Window({
height:300,
width:400,
padding:5,
items:[{
xtype:'Ext.form.TextField',
value:'Testing...'
}]
});

win.show();

mschwartz
18 Feb 2011, 5:47 AM
They may as well:

Ext.reg('Ext.form.TextField', Ext.form.TextField);