-
20 Jul 2012 4:13 AM #1
Answered: 4.1.1 - setValue on Combobox (with valueField) works only if forceSelection is false
Answered: 4.1.1 - setValue on Combobox (with valueField) works only if forceSelection is false
Hi all!
I have a problem with ExtJs 4.1.1 and a Combobox with "displayField" param different from "valueField" param and with forceSelection:true.
Here is my code:
My JSON store returns a JSON array like this:Code:Ext.define('modelCaratteristica', { extend: 'Ext.data.Model', fields: [ {name: 'idcara', type: 'int'}, {name: 'cadesc', type: 'string'} ] }); var storeCaratteristica = Ext.create('Ext.data.Store', { model: 'modelCaratteristica', proxy: { type: 'ajax', url : 'storeCaratteristica.php', reader: { type: 'json' } }, autoLoad: true }); var cbCaratteristica1 = Ext.create('Ext.form.field.ComboBox', { name: 'cbCaratteristica1', id: 'id_cbCaratteristica1', fieldLabel: 'Se Caratteristica', displayField: 'cadesc', valueField: 'idcara', width: 750, labelWidth: 100, store: storeCaratteristica, queryMode: 'local', allowBlank: false, forceSelection: true });
Now, I have displayField and valueField separated because I need to display description and to save to database the id.Code:[{"idcara":"1","cadesc":"AAAA"},{"idcara":"2","cadesc":"BBBB"},{"idcara":"3","cadesc":"CCCC"}]
Now, if I make...
... it only works (set combobox value to "CCCC") if my combobox has forceSelection: false.Code:cbCaratteristica1.setValue(rec.idcara1); // where rec.idcara1 is numeric (for example "3")
But I need forceSelection: true to avoid users to insert bad values. :-(
PS: I have the same problem with ExtJs 4.0.7
-
Best Answer Posted by scottmartin
This is a timing issue. In the forceSelection, you are required to find a value in the store. In the other instance you are not.
You making an ajax call. It is most likely the incoming results are causing havoc.
You can either load the table before hand, or make the update upon success of the ajax call.Code:type: 'ajax', url : 'storeCaratteristica.php', reader: { type: 'json' }
Scott.
-
20 Jul 2012 4:43 AM #2
-
20 Jul 2012 4:58 AM #3
-
20 Jul 2012 5:06 AM #4
-
20 Jul 2012 7:06 AM #5
Uhm... I see.
Here I have my example: http://www.electricblueskies.com/smeraldo/es01.html
It shows the difference between forceSelection = true and forceSelection = false
PS: perhaps a delay problem? If I put an alert before the setValue instruction, sometimes, it works...
-
20 Jul 2012 7:35 AM #6Sencha - Support Team
- Join Date
- Jul 2010
- Location
- Houston, Tx
- Posts
- 7,185
- Vote Rating
- 194
- Answers
- 433
I do not see reset() in your code as mention by Ex_Soft.
Scott.
-
20 Jul 2012 7:50 AM #7
Updated my code with reset(), but the same thing...
I think it is a delay problem, because after the window is opened, the instruction setValue() works:
http://www.electricblueskies.com/smeraldo/es02.html (see the button in the window)
But... how can I solve my problem?
-
21 Jul 2012 10:57 AM #8Sencha - Support Team
- Join Date
- Jul 2010
- Location
- Houston, Tx
- Posts
- 7,185
- Vote Rating
- 194
- Answers
- 433
This is a timing issue. In the forceSelection, you are required to find a value in the store. In the other instance you are not.
You making an ajax call. It is most likely the incoming results are causing havoc.
You can either load the table before hand, or make the update upon success of the ajax call.Code:type: 'ajax', url : 'storeCaratteristica.php', reader: { type: 'json' }
Scott.
-
22 Jul 2012 4:38 AM #9
-
23 Jul 2012 12:05 AM #10
I have solved with this:
Example: http://www.electricblueskies.com/smeraldo/es02.htmlCode:storeCaratteristica.on("load",onLoadCbCaratteristica); function onLoadCbCaratteristica() { var_caratteristica = 1; cbCaratteristica.reset(); cbCaratteristica.setValue(var_caratteristica); }
But if in the form I have more than 1 store to wait to load, the problem returns...


Reply With Quote