PDA

View Full Version : Record mapping data from JSON in form panel



richardwyke
18 Jul 2009, 8:38 AM
Hi everyone,

I'm having a problem with a form panel which uses different names in the JSON input that i want to define in the form.

The backend of the application is in CakePHP so i want to be able to send the variables to be read automagically by CakePHP which means using the variable names like this 'data[Location][name]' where name is the name of the field in the form. I'd like to keep the output and input for CakePHP in this format because it means alot less code on the backend and everything is handled for me into the database etc.

Here is the form i am using (stripped down a bit to make it easier to read):

var tab2 = new Ext.FormPanel({
region: 'center',
monitorValid: true,
url: '/ca/locations/siteread',
labelAlign: 'top',
autoScroll: true,
bodyStyle: 'padding:5px',
items: [{
layout: 'column',
border: false,
items: [{
columnWidth: .5,
layout: 'form',
border: false,
items: [{
xtype: 'textfield',
fieldLabel: 'Name',
name: 'name',
anchor: '95%',
allowBlank: false
}]
},
{
columnWidth: .5,
layout: 'form',
border: false,
items: [{
xtype: 'textfield',
fieldLabel: 'Address',
name: 'address',
anchor: '95%'
}]
}]
}],

buttons: [{
text: 'Save',
formBind: true,
type: 'submit',
handler: function () {
tab2.form.submit({
method: 'POST',
url: '/ca/locations/save',
waitMsg: 'Saving...'
});
}
},
{
text: 'Cancel',
handler: function () {
win.close();
}
}]
});

and then i load some data into the form to edit with the following


tab2.getForm().load({params:{site:id.id}, url:'/ca/locations/siteread', waitMsg:'Loading'});

Which is working fine, but what i want is to be able to map the values coming in called 'name' to 'data[Location][name]' for example. But with the JSON going directly into the formpanel and not through a JsonReader i never have the opportunity to perform the record mapping to rename them.

Any help appreciated!