PDA

View Full Version : how to create an instance of an Ext.extend



Shining77
12 Jan 2011, 12:53 PM
I have done the following:

App.NumberField = Ext.extend(App.ux.NumberField, {
initComponent:function() {
...
}
});
Ext.reg('app.numberfield', App.NumberField);

But how do I create an instance now?

var test = new app.numberfield({...});

don't function :-(

fay
12 Jan 2011, 1:50 PM
var test = new App.NumberField(...);


Ext.reg is for registering a subclassed component type for lazy instantation. See: http://dev.sencha.com/deploy/dev/docs/?class=Ext.Component&member=xtype

Shining77
12 Jan 2011, 2:37 PM
The problem is that I am getting with your code

App.NumberField is not a constructor

mitchellsimoens
12 Jan 2011, 3:47 PM
Ext.ns("App");
App.NumberField = Ext.extend(Ext.form.NumberField, {
....
});
Ext.reg("app.numberfield", App.NumberField);


var field = new App.NumberField({ .... });
or

var field = {
xtype: "app.numberfield",
....
};

skirtle
13 Jan 2011, 12:55 AM
Is your class defined in a separate JS file? Have you remembered to include that file in your HTML?