PDA

View Full Version : Loading form items from database



rectab
21 Sep 2009, 3:18 AM
I have simple form:



var json_user_rights = new Ext.data.JsonStore({
proxy: new Ext.data.HttpProxy({url: 'cms_admin/json_user_rights', method: 'POST'})
});

.....

items:[new Ext.FormPanel({
labelWidth: 90,
id: 'user-form',
border:false,
items: {
xtype:'tabpanel',
activeTab: 0,
defaults:{autoHeight:true, bodyStyle:'padding:10px'},
items:[{
title:'Personal Details',
layout:'form',
defaults: {width: 200},
defaultType: 'textfield',

items: [{
fieldLabel: 'First Name',
name: 'first',
value: node.attributes.name,
allowBlank:false
},{
fieldLabel: 'Last Name',
name: 'last',
value: node.attributes.surname,
allowBlank:false
},{
fieldLabel: 'Login',
name: 'login',
value: node.attributes.username
},{
fieldLabel: 'Password',
name: 'password'
},{
fieldLabel: 'Email',
name: 'email',
value: node.attributes.email,
vtype:'email'
},{
fieldLabel: 'Phone',
name: 'phone',
value: node.attributes.phone
}]
},{
title:'User Rights',
layout:'form',
defaults: {width: 200},
defaultType: 'checkbox',

store: json_user_rights
}]
}
})]

I am trying to load form fields from database (store: json_user_rights).
Someone can tell me how to correct this?

aconran
21 Sep 2009, 3:38 AM
Use the load method of the form.


Ext.getCmp('user-form').load(/* configs */);


The response at the url should follow the documented format of Ext.form.Action.Load (http://www.extjs.com/deploy/dev/docs/?class=Ext.form.Action.Load)

rectab
21 Sep 2009, 3:51 AM
I do not need to load the form values, but the items.

aconran
21 Sep 2009, 3:55 AM
Send the form field definititions over the wire as JSON, use Ext.Ajax.request to retrieve them, use Ext.decode to convert the JSON to standard JS objects and then use Ext.Container add and doLayout to add the fields and render them to the screen.

rectab
21 Sep 2009, 3:59 AM
var json_user_rights = Ext.Ajax.request({
url: 'cms_admin/json_user_rights',
method: 'POST'
});


Now the value of the returns are:



[{"fieldLabel":"Documents","labelSeparator":"","boxLabel":"","name":""},{"fieldLabel":"Users","labelSeparator":"","boxLabel":"","name":""},{"fieldLabel":"Templates","labelSeparator":"","boxLabel":"","name":""},{"fieldLabel":"Statistics","labelSeparator":"","boxLabel":"","name":""},{"fieldLabel":"Forms","labelSeparator":"","boxLabel":"","name":""},{"fieldLabel":"Tools","labelSeparator":"","boxLabel":"","name":""},{"fieldLabel":"Banneri","labelSeparator":"","boxLabel":"","name":""}]


How do I do next?
items: json_user_rights <- does not work

rectab
21 Sep 2009, 12:01 PM
Can someone help?