PDA

View Full Version : How to get and send values from controller to form and viceversa



chinnib37
27 Jun 2013, 9:35 PM
Hi all,
I am using deftjs with Extjs.
I want fetch the data from server and show it in the form.
Data is coming from server, But I am unable to set it to the form. Please tell me the solution to this.
My code is here...

in controller :
Ext.define("ABC.controller.DetailsController", {
extend: "Deft.mvc.ViewController",
mixins:[ 'Deft.mixin.Controllable', 'Deft.mixin.Injectable' ],
inject :['detailStore'],
config:{
detailStore : null,
details : null
},
control : {

DetailsUpdate:{
click : 'onDetailsUpdateClick'
}
},
init: function() {

var _this = this;
var initialDetails = this.loadDetails();
initialDetails.then({success: loadDetailsSuccess, failure: loadDetailsFailure,progress: progressCallback});
function loadDetailsSuccess(result){
console.dir(result);
};
function loadDetailsFailure(result){
console.dir(result);
};
function progressCallback(result){
console.dir(result);
};

return this.callParent(arguments);
},

loadDetails: function() {
var deferred;
deferred = Ext.create("Deft.promise.Deferred");
this.getDetailStore().load({
callback: function(records, operation, success) {
if (success) {
return deferred.resolve(records);
} else {
return deferred.reject("Error loading Scenarios");
}
},
scope: this
});
return deferred.promise;
},

onDetailsUpdateClick : function(){
console.dir(this.getView);
console.log('officeDetails controller');
console.dir(this.getDetails());
}

});

in form :
Ext.define("ABC.view.Settings", {
extend: 'Ext.form.Panel',
alias: "widget.abc-view-Settings",
mixins:[ 'Deft.mixin.Controllable', 'Deft.mixin.Injectable' ],
controller : 'ABC.controller.DetailsController',
initComponent : function(){
Ext.applyIf(this,{ bodyPadding: 5,
autoScroll: true,
fieldDefaults: { msgTarget: 'under',
},
layout: {
type: 'vbox',
pack: 'start',
padding: 5,
align: 'stretch'
},
items : [{
layout : {
type : 'vbox',
pack : 'start'
},
defaults : {
margins : '0 0 10 0'
},
border : false,
items : [{
layout : {
type : 'hbox',
pack : 'start'
},
width : '100%',
border : false,
defaults : {
margin : '0 10 0 0'
},
items : [{
xtype : 'textfield',
name : 'name',
fieldLabel : 'Name',
labelSeparator : "",
readOnly : true,
// disable : true,
width : '60%',

// allowBlank : false,
labelAlign : 'left'
},{
xtype : 'combo',
fieldLabel : 'TimeZone',
labelSeparator : "",
width : '30%',
// allowBlank : false,
labelAlign : 'left'
}]
},{
layout : {
type : 'hbox',
pack : 'start'
},
border : false,
width : '100%',
defaults : {
margin : '0 10 0 0'
},
items : [{
xtype : 'textfield',
name : 'address1',
fieldLabel : 'Address 1',
labelSeparator : "",
width : '50%',
// allowBlank : false,
labelAlign : 'top'
},{
xtype : 'textfield',
name : 'address2',
fieldLabel : 'Address 2',
labelSeparator : "",
width : '50%',
// allowBlank : false,
labelAlign : 'top'
}]
}],
buttons : [{
text : 'Update',
itemId : 'DetailsUpdate'
}]
});
}
});

tvanzoelen
28 Jun 2013, 12:38 AM
After loading the store, get the reference to your form and use


form.loadRecord(record)