PDA

View Full Version : How I can use data from JSON in textfields ?



Nemesis007
19 Sep 2010, 5:07 AM
Hi,

I have a question :

How I can use json data in my FormPanel and put them in my textfields ? (i'm sorry for my english...)

Here my code :



var conn = new Ext.data.Connection();
conn.request({
url: '../getUserData.php',
method: 'POST',
success: function(responseObject) {
var result = Ext.util.JSON.decode(responseObject.responseText);
},
failure: function(form, http){
var json = Ext.util.JSON.decode(http.response.responseText);
Ext.Msg.alert(json.error.clientCode);
}
});

var account_panel = new Ext.form.FormPanel({
url:'ajax/save-account.php',
standardSubmit: true,
id:'account_panel',
autoScroll:true,
frame:true,
title: 'Mon compte',
height:600,
items: [{
layout:'column',
border:false,
items:[{
columnWidth:.5,
layout: 'form',
border:false,
items: [{
xtype:'textfield',
fieldLabel: 'Prénom ',
name: 'account_firstname',
anchor:'55%'
}, {
xtype:'textfield',
fieldLabel: 'Nom ',
name: 'account_name',
anchor:'55%'
}, {
/*xtype: 'datefield',
fieldLabel: 'Date de naissance ',
name: 'account_birthday',
anchor:'55%'
}, {*/
xtype:'textfield',
fieldLabel: 'Adresse e-mail',
name: 'account_email',
/*valueField:data[0]['id'],*/ // je souhaite pré-remplir ce champs avec ce que j'ai trouvé dans la BDD
vtype:'email',
anchor:'55%'
}, {
xtype:'textfield',
fieldLabel:'Identifiant',
name:'loginUsername',
minLength: 6,
maxLength: 20,
disabled: true,
anchor:'55%'

}, {
xtype: 'textfield', id: 'loginPassword', fieldLabel: 'Mot de passe',
inputType: 'password',allowBlank: false, minLength: 6,
maxLength: 20,
minLengthText: 'Votre mot de passe doit comporter entre 6 et 20 caractères.',
blankText:'Veuillez saisir votre mot de passe',
anchor:'55%'
}, {
xtype: 'textfield', id: 'loginPasswordVerif',
fieldLabel: 'Confirmation mot de passe', inputType: 'password',
allowBlank: false,
vtype: 'password', initialPassField: 'loginPassword',
blankText:'Saisissez à nouveau votre mot de passe',
anchor:'55%'
}]
}]
}, {
buttons: [{
text: 'Enregistrer',
handler:function() {
account_panel.getForm().getEl().dom.action = 'ajax/save-account.php';
account_panel.getForm().getEl().dom.method = 'POST';
account_panel.getForm().submit();
}
},{
text: 'Annuler',
handler:function() {
javascript:location.reload(true)
}
}]
}]
});


I have my data in result but how i can use them in my items ?

Thanks a lot !