PDA

View Full Version : FormPanel mapping fields



san121
5 Dec 2010, 1:00 PM
I've created form:


var suppliersFilterFormPanel = new Ext.FormPanel({
items : [{
fieldLabel : 'Name',
name : 'filter_name',
mapping : 'name.text'
}]
});


Next, load data:


suppliersFilterFormPanel.getForm().load({
url : '/index.php?getFilter',
method : 'POST',
root : 'data',
disableCaching : true
});


Script send json format:


{
"success": true,
"data": {
"name": {"text": "some text"}
}
}


But field 'filter_name' in panel form is empty.

Whats wrong?

Condor
6 Dec 2010, 1:34 AM
Fields don't support a 'mapping' property.

Instead, you could configure a 'reader' for your form and specify the mappings in there.

san121
6 Dec 2010, 11:03 AM
Thank for help.

Added reader.
Not obtained. :(



<script type="text/javascript">

Ext.onReady(function() {

var suppliersFilterFormPanel = new Ext.FormPanel({
title : 'Filter',
renderTo : document.body,

reader : new Ext.data.JsonReader({
root : 'data',
success : 'success'
},
[{name: 'filter_name', mapping: 'name.text'}]
),

defaultType : 'textfield',
items : [
{
fieldLabel : 'Name',
name : 'filter_name'
}
]
});

suppliersFilterFormPanel.getForm().load({url:'json.php'});

});

</script>


{"success":true,"data":{"name":{"text":"some text"}}}

Condor
6 Dec 2010, 11:26 AM
JsonReader expects the root to be an array. It it isn't then it needs:

root: function(v){
return [v.data];
}

san121
6 Dec 2010, 12:14 PM
Thank twice. :)

Problem solved.