PDA

View Full Version : Problem while setting value in Ext.window.Window



8 Aug 2012, 12:42 PM
Hi,

I tried to set the values using Ext.ComponentManager but it did not work. Here is my code.. I want to set the value of firstname from id. I am getting the id value from server, but not able to set that in firstname and lastname fields. Please help.



Ext.define('sample.view.student.Edit', {
extend : 'Ext.window.Window',
alias : 'widget.studentedit',




requires : ['Ext.form.Panel', 'Ext.form.field.Text',
'Ext.form.field.ComboBox'],




title : 'student dtls',
layout : 'fit',
autoShow : true,
width : 280,




iconCls : 'icon-user',




initComponent : function() {
this.items = [{
xtype : 'form',
padding : '5 5 0 5',
border : false,
style : 'background-color: #fff;',




fieldDefaults : {
anchor : '100%',
labelAlign : 'left',
allowBlank : false,
combineErrors : true,
msgTarget : 'side'
},




items : [ {
xtype : 'textfield',
name : 'studentId',
fieldLabel : 'studentId',
listeners : {
blur : function() {
// fnDataForm(this.value);
Ext.Ajax.request({
url : 'student/fetchDtls.action',
params : {
guiInstrId : this.value
},
success : function(response, opts) {
var jsonResp = Ext
.decode(response.responseText);




console.dir(jsonResp);
console.log(jsonResp.studentFirstName);
// How to set jsonResp.studentFirstName value in below textfield ?
this.up('form').getForm().getValues().studentFirstName.setValue(jsonResp.studentFirstName);
},
failure : function(response, opts) {
console
.log('server-side failure with status code '
+ response.status);
}
});
}
}




}, {
xtype : 'textfield',
name : 'studentFirstName',
fieldLabel : 'student First Name'




}, {
xtype : 'textfield',
name : 'studentLastName',
fieldLabel : 'student Last Name'




}]
}];

scottmartin
8 Aug 2012, 1:20 PM
You could assign an itemId to the field, then use something like:



{
xtype: 'textfield',
name: 'studentFirstName',
itemId: 'studentfirstname',
fieldLabel: 'student First Name'
}

..

var form = this.up('form'),
sfn = form.down('#studentfirstname');

sfn.setValue(sonResp.studentFirstName);


Scott.

8 Aug 2012, 2:22 PM
Hi Scott,

It gives me error that, "TypeError: this.up is not a function" . Plz help.

J.M.

You could assign an itemId to the field, then use something like:



{
xtype: 'textfield',
name: 'studentFirstName',
itemId: 'studentfirstname',
fieldLabel: 'student First Name'
}

..

var form = this.up('form'),
sfn = form.down('#studentfirstname');

sfn.setValue(sonResp.studentFirstName);


Scott.

8 Aug 2012, 2:35 PM
Hi Scott,
It worked. I had to put
var form = this.up('form'), statement outside the Ext.Ajax.Request and just at first line of my function. and then it worked like charm !!.. Thanks a lot !!

J.M.

Hi Scott,

It gives me error that, "TypeError: this.up is not a function" . Plz help.

J.M.