PDA

View Full Version : Ext.widget and Ext.getCmp different result in form fields value



aorlando
17 May 2012, 12:15 AM
I am doing an MVC appplication with Ext 4.1 and in my controller I am trying to get the value of form (xtype: 'form' - id:'formid') in a window ('widget.edit1').

the window with form:


Ext.define('schedule.view.EditWindow', {
extend: 'Ext.window.Window',
alias : 'widget.edit1',

title : 'Edit'
,layout: 'fit'
,autoShow: false

,initComponent: function() {
this.items = [
{
xtype: 'form'
,id: 'formid'
,items:
[{
xtype: 'textfield',
fieldLabel: 'Name'
},{
xtype: 'filefield',
id: 'form-file',
emptyText: 'Select an image',
fieldLabel: 'Photo',
name: 'photo-path',
buttonText: '',
buttonConfig: {
iconCls: 'upload-icon'
}
}]
}

];


this.buttons = [


{
text: 'Save'
},
{
text: 'Cancel',
scope: this,
handler: this.close
}
];


this.callParent(arguments);
}
});


the event in controller:


, 'edit1 button[text="Save"]': {
click: this.butSaveUpload
}



the function in controller


,butSaveUpload: function(button){ var form = Ext.widget('edit1').down('form').getForm();
if(form.isValid()){
form.submit({
url: 'file-upload.php',
waitMsg: 'Uploading your photo...',
success: function(fp, o) {
msg('Success', 'Processed file');
}
,failure: function(fp,o){
msg('Error', 'Error');

}
});
}


}

If I use:


var form = Ext.widget('edit1').down('form').getForm();


the value of form fields are undefined.
Otherwise if I use:


var form=Ext.getCmp('formid').getForm();

the value in the form fields are correct. Is there somenthing wrong in my code or this is a bug?

thanks in advance

scottmartin
17 May 2012, 6:06 AM
You can use app.controller.refs: [] in your controller to reference your components as needed.

Regards,
Scott.

aorlando
17 May 2012, 7:20 AM
thanks Scott.
I am a bit confused. "Ext.widget('x')" create a new instance of 'x'. That is correct?
Could you give me some example about "app.controller.refs[]"
I am new in ExtJs and I am trying to write a good MVC application.

thanks

scottmartin
21 May 2012, 9:44 AM
Have a look at the following article:
http://www.sencha.com/learn/architecting-your-app-in-ext-js-4-part-3/

Ext.widget is the same as calling Ext.create(..);

Scott.