views:

158

answers:

2

Hello everyone! I have a some class

AddOrgWindowUI = Ext.extend(Ext.Window, {
title: 'form',
width: 400,
height: 198,
layout: 'form',
padding: 5,
initComponent: function() {
    this.items = [
        {
            xtype: 'textfield',
            fieldLabel: 'parapapa',
            anchor: '95%',
            value: m,
            emptyText: 'perapapa'
        }
    ];
    AddOrgWindowUI.superclass.initComponent.call(this);
}});

when I create an object var AddOrgWindowForm = new AddOrgWindowUI('aaa'); I want to get arg ('aaa') to my new form value (value m). How get it? Im trying initComponent: function(m) { and thats not working.

A: 

pass m as an arg of initComponent:

edit:

AddOrgWindowUI = function(input) {
    var m = input;
    return Ext.extend(Ext.Window, {
        title: 'form',
        width: 400,
        height: 198,
        layout: 'form',
        padding: 5,
        initComponent: function() {
            this.items = [
        {
            xtype: 'textfield',
            fieldLabel: 'parapapa',
            anchor: '95%',
            value: m,
            emptyText: 'perapapa'
        }
    ];
            AddOrgWindowUI.superclass.initComponent.call(this);
        }
    });
}
Silkster
thx, but how to declare a new object?var AddOrgWindowForm = new AddOrgWindowUI.initComponent('aaa'); - doesnt work.
0dd_b1t
My edit above might do it.
Silkster
it doesnt work too :( try it. Firebug say - "AddOrgWindowUI.initComponent is not a function"
0dd_b1t
Doing it this way you loose the ability to pass in any other configuration items to the constructor.
SBUJOLD
+5  A: 

The initComponent function is called internally on one of the base classes of Ext.Window. You shouldn't try to call it directly. That is why it won't handle your own parameters.

So I recommend you to use the standard form parameters when extending ExtJS classes.

It is as simple as initializing the object with the property or methods you want to override (or insert in case the property is not in there already). And then just using the this keyword to access them.

This is possible because for every Ext.Component and its subclasses, the first parameter passed to the constructor should be an object, and every member in that object will be copied to the new object constructed. And most ExtJS classes extend directly or indirectly from Ext.Component, and you are extending from Ext.Window which extends from Ext.Component too.

Here you have your example fixed:

var AddOrgWindowUI = Ext.extend(Ext.Window, {
    title: 'form',
    width: 400,
    height: 198,
    layout: 'form',
    padding: 5,

    initComponent: function() {
        this.items = [
            {
                xtype: 'textfield',
                fieldLabel: 'parapapa',
                anchor: '95%',
                value: this.initialValue,
                emptyText: 'perapapa'
            }
        ];
        AddOrgWindowUI.superclass.initComponent.call(this);
    }
});

function test() {
    var AddOrgWindowForm = new AddOrgWindowUI({initialValue:'aaa'});
    AddOrgWindowForm.show();
}
Protron
thx a lot. And thx for links ;)
0dd_b1t