PDA

View Full Version : Loading JSON result into formPanel ... don't work



UnityWeb
24 Nov 2007, 10:15 AM
Hi, finally succeeded in grid editing. Now i'd like to open a window to let data editing but i'm having a problem with loading the result of a query into a simple form. It simple doesn't 'load' the fetched results into the form.

Here's my code :

Javascript :

[CODE]var backendUrl = 'loader.php';

Ext.onReady(function(){
var ds = new Ext.data.Store({
proxy: new Ext.data.ScriptTagProxy ({
url: backendUrl,
method: 'POST'
}),

reader: new Ext.data.JsonReader ({
root: 'results',
totalProperty: 'total',
id: 'ID'
}, [
{name: 'nom', mapping: 'nom'},
{name: 'prenom', mapping: 'prenom'}
])
});

var formDonnee = new Ext.form.FormPanel ({
baseCls: 'x-plain',
labelWidth: 85,
url: backendUrl,
defaultType: 'textfield',
items: [{
fieldLabel: 'Nom',
name: 'nom',
anchor:'100%'
},{
fieldLabel: 'Pr

tryanDLS
24 Nov 2007, 10:22 AM
There are examples and answers to issues like this if you search the forums. This has been asked/answered - results is a single object, not an array.

zhfxu_cs
24 Nov 2007, 11:13 PM
// pre-define fields in the form
var lastname = new Ext.form.TextField({
fieldLabel: 'Last Name',
allowBlank: false,
name: 'lastname',
anchor: '90%'
});

var firstname = new Ext.form.TextField({
fieldLabel: 'First Name',
allowBlank: false,
name: 'firstname',
anchor: '90%'
});

var username = new Ext.form.TextField({
fieldLabel: 'User Name',
allowBlank: false,
name: 'username',
readOnly: true,
anchor: '90%'
});

var password = new Ext.form.TextField({
fieldLabel: 'Password',
allowBlank: false,
inputType: 'password',
name: 'password',
anchor: '90%'
});

var email = new Ext.form.TextField({
vtype: 'email',
fieldLabel: 'Email',
name: 'email',
anchor: '90%'
});

var birthday = new Ext.form.DateField({
fieldLabel: 'Birthday',
name: 'birthday',
format:'M d, Y',
anchor: '60%'
});

var note = new Ext.form.TextField({
xtype: 'textarea',
hideLabel: true,
name: 'note',
anchor: '100% -35' // anchor width by percentage and height by raw adjustment
});

// create form panel
var formPanel = new Ext.form.FormPanel({

baseCls: 'x-plain',
labelWidth: 75,
url:'demouser/listDemouser.htm?action=editDemouser',

reader: new Ext.data.JsonReader({
root: 'results'
}, ['id','username','lastname','firstname','password','email','birthday','note']
),

items: [
lastname,
firstname,
username,
password,
email,
birthday,
note
]
});

// load form and assign value to fields
formPanel.form.load({url:'demouser/listDemouser.htm?action=loadData&id='+selectedId,
waitMsg:'Loading'});