PDA

View Full Version : Container's "defaults" cannot apply to children items



sdd0
26 Jun 2014, 11:48 PM
I have a window with a form. After window opening, the form has no components items in the beginning, it uses its own function "putData2Store" to creates stores. After stores has been created, there is a callback function to call the function "dispatch" to add extra items in form.

I met a problem, my form has its own defaults attribute --> defaults: {labelWidth:400}, I expect that labelWidth:400 will work on my textfield "des" but it doesn't.



Ext.define('zldapp.view.securepolicy.policy.secpolicyedit', {
extend:'Ext.zyWindow',
initComponent: function(){
var me = this;
Ext.apply(this, {
title: 'add',
id: 'secpolicyedit',
width: 800,
height: 430,

iconCls: 'add',

ok: function(){
var form = this.query('#security-policy-edit');
form[0].cfgCLI(this.which);
},
cancel: function(){
this.close();
},
items:[{
xtype: 'zyform',
id:'security-policy-edit',
defaults:{

labelWidth:400
},

putData2Store: function(form){

//create store here
...

},
buildItems: function(){
var which = me.which;
var name = (which.action == 'edit') ? which.rowSel.get('__name') : '';
var des = Ext.create('Ext.zyTextField',{

fieldLabel: mlang['_Description'],
name: 'description',
id: 'desc',
vtype: 'chkDesc',
value: (which.action == 'add') ? '' : which.rowSel.get('_description'),
previousValue: (which.action == 'add') ? '' : which.rowSel.get('_description'),
listeners: {
render: function(e) {
if (name == 'Default')
e.setVisible(false);
},
change: function(e) {
if (which.action == 'edit')
handleFn(which.rowSel, '_description', e.getValue(), e.previousValue);
}
},
hypertext:{
text:'',
tabId:'',
treeNodeId:''
},
inote:'',
suffix:'('+mlang['_Optional']+')'

});


return[
{
xtype: 'zyformspacer'
},

des,
{
xtype: 'zyformspacer'
}
];
},
dispatch: function(){
this.add(this.buildItems());
this.doLayout();
}

}]

});

this.callParent();
}
});


If I don't create "des" first, I use "xtype" instead, it works perfectly, the labelWidth of "des" is set as 400 as I want.
Could anyone tell me what's the difference between them? I don't want to change all the old version code for 4.2 upgrade >.<


The code below works


var des = {
xtype:'zytextfield',
fieldLabel: mlang['_Description'],
name: 'description',
id: 'desc',
vtype: 'chkDesc',
value: (which.action == 'add') ? '' : which.rowSel.get('_description'),
previousValue: (which.action == 'add') ? '' : which.rowSel.get('_description'),
listeners: {
render: function(e) {
if (name == 'Default')
e.setVisible(false);
},
change: function(e) {
if (which.action == 'edit')
handleFn(which.rowSel, '_description', e.getValue(), e.previousValue);
}
}
}

cmeans
29 Jun 2014, 8:03 AM
Wouldn't the form property "fieldDefaults" work the way you want?

http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.form.Panel-cfg-fieldDefaults

-Chris

sdd0
29 Jun 2014, 5:54 PM
Hi Chris,Thank you very much! I don't know there is a "fieldDefaults" from 4.0, it works. I appreciate that you told me this.