I am trying to get ExtJS combobox to return value instead of display value.
Here's my problem. I am using ajax to get the data for the combobox field, and in the same time using getForm().load to load the selected values for the combobox. In the model I've return a display value and code value. Display value is assigned to 'name' and code value is assigned to 'hiddenName'. When I submit the data, the display value is being submitted not the code value from 'hiddenName' field.
After changing the selection of the combobox, the code value is being submitted.
Here's the code:
{
xtype: 'combobox',
fieldLabel: 'Type',
name: 'DataType',
hiddenName: 'DataTypeCde',
store: Ext.create('Ext.data.JsonStore', {
proxy: {
type: 'ajax',
actionMethods: { create: 'POST', read: 'POST', update: 'POST', destroy: 'POST' },
url: '@Url.Content("~/{URL}/DataType")',
reader: {
type: 'json'
}
},
fields: ['Id', 'Name']
}),
valueField: 'Id',
displayField: 'Name',
typeAhead: true,
mode: 'remote',
emptyText: 'Select a data type...',
anchor: '96%'
},
Another thing is that, when I set the 'name' to be 'DataTypeCde' the code value get display, but once the ajax data for the combobox get loaded, display value then get replaced by the display value.
So I can either get 'hiddenName' to load the DataTypeCde value and have this value post back, or get the combobox data to pre load on form render.
Can someone point out if there's a way or what I'm doing wrong to prevent the code value from being post back.
Update: *Update4: (added POST response sample)*
Let me explain better of what I'm trying to achieve.
(1) With the code above the follow will be displayed... if DataType = Shopping and DataTypeCde = SP the combobox after rendering will show Shopping, which is how I want this to be. But once I submit this result back to the controller, the "Shopping" is being returned instead of "SP"... this is not what I want.
Example of POST response...
id=1&DataType=Shopping
(2) With the name field set to "DataTypeCde" this will be the following result... if DataType = Shopping and DataTypeCde = SP the combobox after rendering will show SP, which is not what I want as I want to display the text not the code. But once I submit the result back to the controller, the code "SP" is returned, which is how I intended.
Example of POST response...
id=1&DataTypeCde=SP
(3) By using the second method of setting name field to "DataTypeCde" we will get the result of code display until the combobox data get loaded. So to solve this issue I've set the "autoLoad" feature to true, so the combobox data will get loaded at render automatically. At this point ExtJS will replace the "SP" code displaying to the display value of "Shopping". But one problem with this solution is that requiring all the combobox to load at the start will slowdown the page load significantly.
Example of POST response...
id=1&DataTypeCde=SP
(Q) My question is... Is there a way to set the display value to show for the combobox without loading the combobox data, but have the code value get posted back instead of the display value.
Update2:
Sorry for the confusion, I forgot to mention I'm using ASP.NET MVC4 with ExtJs. In the case where I mention returning the post response to controller. I mean the MVC controller. I didn't think the back-end would be relevant to this question.
Update3:
To give a even bigger picture of my implementation here's the code and data sample that I use to load the form.
example2.getForm().load({
url: '@Url.Content("~/{URL}/Data/")',
params: {
id: window.record.data['id']
},
method: 'POST'
});
The above loads a collection of json object similar to this...
{"success":true,"data":{"id":"1","DataType":"Shopping","DataTypeCde":"SP"}}
Here's the code to ajax the data for the combo box...
store: Ext.create('Ext.data.JsonStore', {
proxy: {
type: 'ajax',
actionMethods: { create: 'POST', read: 'POST', update: 'POST', destroy: 'POST' },
url: '@Url.Content("~/{URL}/DataType")',
reader: {
type: 'json'
}
},
fields: ['Id', 'Name']
}),
With the result json object like this...
[{"Id":"SP","Name":"Shopping"}]
Thanks