PDA

View Full Version : Why can't I load data to the form panel?



safewolf
28 Sep 2011, 12:29 AM
Hi, eveyone

I have a form now.



Ext.define('AdminLevel', {
extend : 'Ext.data.Model',
fields : ['id', 'level_name', 'priority'],
idProperty : 'id'
});

Ext.define('Admin.AdminLevelForm', {
extend : 'Ext.form.FormPanel',
alias : 'admin.adminlevelform',
initComponent : function() {
this.addEvents('cancelClicked', 'saveFinished');
Ext.apply(this, {
bodyPadding : 5,
waitMsgTarget : true,
defaultType : 'textfield',
fieldDefaults : {
labelAlign : 'right',
labelWidth : 85,
msgTarget : 'side',
anchor : '100%'
},

reader : new Ext.data.JsonReader({
model : 'AdminLevel',
root : 'row',
successProperty : 'success'
}),
errorReader : new Ext.data.JsonReader({
model : 'AdminLevel',
root : 'row',
successProperty : 'success'
}),
items : [{
xtype : 'hidden',
name : 'id'
}, {
fieldLabel : LANGUAGE_ADMINLEVEL_LEVEL_NAME,
name : 'level_name',
allowBlank : false
}, {
fieldLabel : LANGUAGE_ADMINLEVEL_LEVEL_PRIORITY,
name : 'priority',
allowBlank : false
}],
buttons : [{
text : 'Save',
scope : this,
handler : function() {
var form = this.getForm();
if (form.isValid()) {
form.submit({
scope : this,
url : BASEURL + URL_ADMINLEVEL_SAVE,
success : function(form, action) {
Ext.Msg.alert('Success',
// action.result.msg);
"Saved");
// result = true;
// message = "You Are Right!";
this.fireEvent("saveFinished",
true);
},
failure : function(form, action) {
Ext.Msg.alert('Failed',
action.result.msg);
}
});
} else {
alert("error");
}
}
}, {
text : 'Cancel',
scope : this,
handler : function() {
this.fireEvent("cancelClicked");
}
}]
});
this.callParent(arguments);
},

loadRow : function(guid) {
/*
* this.getForm().load({ url : BASEURL + URL_ADMINLEVEL_READ, waitMsg :
* 'Loading...', params : { id : guid } });
*/

this.getForm().load({
scope : this,
url : BASEURL + URL_ADMINLEVEL_READ,
method : 'post',
params : {
id : guid
},
success : function(form, action) {
},
failure : function(form, action) {
}
})

}

});





when I execute loadRow(1)
my server returned the json string:
{"success":true,"row":{"id":"1","level_name":"Super Admin","priority":"999"}}

and there's no error message.

But the form panel was still empty.
Anybody can help me please?

c5m7b4
23 Mar 2012, 8:51 AM
Hey,
I was wondering if you ever found a solution to this problem. I am having the similar issue. I wanted to simplify everything so I created a new form that only has one textfield (EXT JS 3.2 by the way):


<script>
Ext.onReady(function(){
var movie_form = new Ext.FormPanel({
renderTo: Ext.getBody(),
frame: true,
title: "Test Movie Form",
width: 350,
items:[
{
xtype: 'textfield',
fieldLabel: 'Name:',
name: 'title',
id:'title'
}
]
});
movie_form.getForm().load({url:'loadform2.php?id=1',params:{id:1},success:Success,failure:Failure});
});

function Success(form,action){
console.log("Success");
console.dir(action);
console.log(action.response);
console.log(action.result);
console.log(action.type);
}

function Failure(thisform, action){
console.log("Form Failed to Load");
console.dir(action);
console.log("ft="+action.failureType);
console.log("typ=" + action.type);
console.dir(action.response);
console.dir(action.result);
}
</script>

My json return is this
responseText: "{success: true, data:[{"title":"First Blood"}]}"

I do get success but the form remains blank: Any suggestions for a newb?


status: 200
statusText: "OK"