PDA

View Full Version : form fild value conversion to object



oracle.cons.tr
8 Mar 2014, 10:36 AM
Hi
I have a combobox inside a form.
when i perform form .updateRecord()
record gets updated like;

Code:

record = {..... module:'modulename' /* this comes from combo */ }
but the server expects it like
Code:

record = { module : { name : 'modulename'}}
There are other fields like this one on the form.
I believe rawtovalue/valuetoraw methods
could be the solution (In fact i might be totally wrong on this idea) but i couldnt get any further.

How can i convert the value to an object so it is reflected to the record as object.

scottmartin
8 Mar 2014, 11:43 AM
Perhaps you can provide some code of your model/store and how are you saving the data.

The payload sent should be like:

data: {id_user:10, user_name:USER, first_name:First, last_name:Last,}

oracle.cons.tr
8 Mar 2014, 5:16 PM
This is part of my model;




/* Basic task definition */
Ext.define('SCH.model.template.TemplateTaskModel', {
extend: 'SCH.model.template.TemplateUnitModel',


idProperty:'id',
fields: [


{name : "module", type : "auto", mapping:"module"},
{name : "moduleName", type : "string", mapping:"module.name"},
{
name : "predecessorSummaries",
type : "auto",
persist : false
},
{
name : "planName",
type : "string",
persist : false,
mapping : "planTemplate.name"
},
{
name : "schedulerName",
type : "string",
persist : false,
mapping : "planTemplate.schedulerName"
}


],


/* One to many relation between task and predecessors
* which are also task models themselves.
* - A task may have many predecessors.
* - A predecessor is a task.
*/
hasMany : [
{
name :'predecessors',
model :'SCH.model.template.TemplateTaskModel',
associationKey:'predecessorSummaries'
}
],


hasOne : [
{
name :'module',
model :'SCH.model.template.TemplateModuleModel',
associationKey:'module'
},
{
name :'planTemplate',
model :'SCH.model.template.TemplatePlanModel',
associationKey:'planTemplate'
}
]


});



This is part of the form;




Ext.define('SCH.view.panel.task.template.TemplateTaskGeneralPanel', {


extend : 'Ext.form.Panel',


requires: [
.....
],


xtype : 'templatetaskgeneralpanel',
title : 'General',
defaultType : 'textfield',
layout : 'form',
overflowY : 'auto',


defaults : {
anchor : '100%',
labelAlign : 'top'
},


items :[
{
xtype : 'plannametextfield',
readOnly : true
},
{
xtype : 'combo',
fieldLabel : null,
padding : '0 10 0 0',
idField : 'name',
valueField : 'name'
},
....


]


});



This is part of my store




Ext.define('SCH.store.template.TemplateTaskStore',{
extend :'Ext.data.Store',
requires:['SCH.model.template.TemplateTaskModel'],


alias : 'store.TemplateTaskStore',
model : 'SCH.model.template.TemplateTaskModel',
autoLoad : false,
autoSync : false,
groupField : 'moduleName',


proxy: {
type : 'rest',
batchActions: true,
url : '',
reader : {
type : 'json',
idProperty:'id'
},
writer : {
type : 'json'
},
/** Mapping of action name to HTTP request method. */
actionMethods: {
create : 'POST',
read : 'GET',
update : 'PUT',
destroy : 'DELETE'
}


}
});



And in the controller i do like


var general = w.down('templatetaskformpanel templatetaskgeneralpanel');
general.updateRecord();




You see combo returns a value like 'SomeModuleName' but the server expects it like


....Other fields....
module:{
name:'SomeModuleName'
}
......



I mean there is probably a configuration on the framework ,that i am missing,
which converts flat form data to composite model structure and vice versa.


To elloborate more; We can think the opposite stiation when i perform
form.loadRecord(); and i have


hasOne : [
{
name :'module',
model :'SCH.model.template.TemplateModuleModel',
associationKey:'module'
}]

There shuld be a way to map module.name to combo while loading record to form
and as i wrote above there should be a way to map combo.value to module:{name:'combosValue'}