0

Is it possible to change xtype and user defined xtypes config options programmatically? After doing so, all instances of xtype would have these config options.

I want to be able to define defaults to certain xtypes before being instantiated. These defaults depend on an application setting (maxLength,visible,vtype)

I dont want to iterate through instantiated components and set the property.

Thanks.

tonymayoral
  • 4,797
  • 2
  • 26
  • 27

1 Answers1

0

It looks like you can as long as you didn't override the defaults as part of the object's instantiation. See http://jsfiddle.net/WteqQ/2/

Ext.define('Custom', {
    xtype: 'custom',
    defaultProp: 'default',
    defaultProp2: 'default2',
    customFn1: function () {
        alert(1);
    }
});

var a = new Custom();
a.defaultProp2 = 'overridden default';
a.customFn1();        //alerts 1
alert(a.defaultProp); //alerts default
alert(a.defaultProp2);//alerts overridden default
//a.customFn2();      //would throw error

Ext.define('Custom.Override', {
    override: 'Custom',
    defaultProp: 'new default',
    customFn1: function () {
        alert(2);
    },
    customFn2: function () {
        alert(3);
    }
});

a.customFn1();        //alerts 2
a.customFn2();        //alerts 3
alert(a.defaultProp); //alerts new default
alert(a.defaultProp2);//alerts overridden default

Although this works, I think it would be better to have your application settings applied before you instantiate your components.

Towler
  • 1,552
  • 1
  • 10
  • 21