PDA

View Full Version : Why FormPanel is not load?



Silvaria
29 Jun 2009, 12:26 AM
I want formPanel initial with data from json file. But no value initial when call load.


var formPanel = new Ext.form.FormPanel({
items: [{
xtype: 'textfield',
fieldLabel: 'User',
name: 'user',
id: 'user'
}],
renderTo: Ext.getBody(),
});

formPanel.getForm().load({
url: 'data/test-form-load.json',
});





{
success: true,
data: [{
user: 'USER 1',
}]
}


Are any thing missing?

tryanDLS
29 Jun 2009, 5:39 AM
Have you debugged? Does firebug show the response being loaded?

Silvaria
29 Jun 2009, 8:32 PM
Firebug show result that response is OK. And I add actioncomplete and actionfailed handler and It response as load action is complete with result that I expect.


var formPanel = new Ext.form.FormPanel({
items: [{
xtype: 'textfield',
fieldLabel: 'User',
name: 'user',
id: 'user'
}],
renderTo: Ext.getBody(),
});

var form = formPanel.getForm();
form.on('actioncomplete', function(f, a){
console.log('complete');
//console.log(f);
//console.log(a.result);
})
form.on('actionfailed', function(f, a){
console.log('failed');
})
form.load({
url: 'data/test-form-load.json',
});
But it seem

success : function(response){
var result = this.processResponse(response);
if(result === true || !result.success || !result.data){
this.failureType = Ext.form.Action.LOAD_FAILURE;
this.form.afterAction(this, false);
return;
}
this.form.clearInvalid();
this.form.setValues(result.data);
this.form.afterAction(this, true);
},
in Action.js is not work properly.

Silvaria
29 Jun 2009, 9:22 PM
And if I change from call load to loadRecord


var form = formPanel.getForm();
// form.on('actioncomplete', function(f, a){
// console.log('complete');
// //console.log(f);
// //console.log(a.result);
// });
// form.on('actionfailed', function(f, a){
// console.log('failed');
// });
// form.load({
// url: 'data/test-form-load.json',
// });

var store = new Ext.data.JsonStore({
url: 'data/test-form-load.json',
//totalProperty: 'totalCount',
root: 'data',
//id: 'id',
fields: ['user'],
});
store.on('load', function(){
form.loadRecord(store.getAt(0));
});
store.load();
It work. But I don't want to add field like this.

nikhilkrishnan
29 Jun 2009, 10:11 PM
I think you have to define a 'reader' for the formPanel,like
reader:new Ext.data.JsonReader({
root:'results',
totalproperty:'total',
id:'id'}, [
{name: 'id', mapping:'id'},
{name: 'user', mapping:'user'}
// custom data types
])

Silvaria
29 Jun 2009, 11:43 PM
I think it don't need reader because in response of firebug window show it is JSON. I think FormPanel with load is normal style, isn't it? Are anyone who used to use this style can post some working example for me?

Silvaria
30 Jun 2009, 1:18 AM
I find out that I must add reader to form.


var formPanel = new Ext.form.FormPanel({
url: 'data/test-form-load.json',
reader : new Ext.data.JsonReader({
root: 'data'
}, ['user',
]),

items: [{
xtype: 'textfield',
fieldLabel: 'User',
id: 'user'
}, {
xtype: 'textfield',
fieldLabel: 'Pass',
id: 'pass'
}],
renderTo: Ext.getBody(),
});

And it work correctly. Thank you.

Animal
30 Jun 2009, 2:14 AM
You wouldn't need a Reader if your data was



{
success: true,
data: {
user: 'USER 1'
}
}