PDA

View Full Version : form - load data



bauchinj
30 Oct 2009, 1:45 AM
function addEditableFormWestUA(user){
//get components of the changed regions
westContainer = Ext.getCmp('westRegion');
ctrContainer = Ext.getCmp('centerRegion');

panel = Ext.getCmp('uga-panel');

var uaStore = new Ext.data.Store({
reader : new Ext.data.JsonReader({
fields : ['firstname','lastname', 'password'],
root : 'user'
}),
proxy : new Ext.data.HttpProxy({
url : 'php/uga.php?action=selectUser&id='+user
}),
autoLoad : true
});
uaStore.load();

//Set positioning
ctrContainer.setWidth(310);
ctrContainer.setPosition(209,3);

westContainer.setWidth(200);
westContainer.setHeight(442);
westContainer.setPosition(3,3);

//Do all necessary administration for editing user
ctrContainer.remove(panel,false);
ctrContainer.add({
xtype : 'form',
id : 'formUA',
width : 50,
border : false,
store : uaStore,
items : [{
xtype : 'textfield',
fieldLabel : 'Firstname',
name : 'firstname',
width : 200
},{
xtype : 'textfield',
fieldLabel : 'Lastname',
name : 'lastname',
width : 200
},{
xtype : 'textfield',
fieldLabel : 'Password',
name : 'password',
vtype : 'pwd',
width : 200
}]
});
//Ext.getCmp("formUA").getForm().load(uaStore);
ctrContainer.doLayout();

westContainer.add(panel);
westContainer.doLayout();
}

I want to load some data in form:
This is the json, php echo

{success:true,user:{"username":"mh","password":"admin","firstname":"First","lastname":"Last","groups":[{"name":"master","master":"1"}],"creationdate":"2009-10-28 14:47"}}

So if I attempt in case to load data via


Ext.getCmp("formUA").getForm().load(uaStore);
firebug say:
uncaught
exception: [Exception... "Component returned failure code: 0x80070057
(NS_ERROR_ILLEGAL_VALUE) [nsIXMLHttpRequest.open]" nsresult:
"0x80070057 (NS_ERROR_ILLEGAL_VALUE)" ... data: no]

So I don't know, how to load data...?

Hope somebody can help me!

smit_al
30 Oct 2009, 4:23 AM
Forum Search (http://www.google.com/cse?cx=001733999371871106761:jgc8jk2xgwe&ie=UTF-8&q=json+formpanel+example&sa=Search)

Have a look at the first example in the search list above. 1 hint, you don't need a store for a formpanel.

Mike Robinson
30 Oct 2009, 6:44 AM
It isn't always obvious that all forms derive from BasicForm, and that many methods not otherwise discussed are found there. Including the ones that you are looking for.

VinylFox
30 Oct 2009, 7:25 AM
The load method your trying to use...

Ext.getCmp("formUA").getForm().load(uaStore);

Is used for requesting data from the server. I think what you might want is the loadRecord method, which would take a single record from your store as the argument which will load the form fields with that records data.

However, if your only loading the form from a store that is only used to fetch that single record, then you might want to ditch the store, and use the forms load method, supplying it the URL of your PHP script, and formatting the response appropriately.

Take a look at the example code at the top of the docs: Ext.form.Action.Load (http://www.extjs.com/deploy/dev/docs/?class=Ext.form.Action.Load)