PDA

View Full Version : Combo valueField getValue unreliable



TopKatz
19 Feb 2010, 1:14 PM
I have a extended combo I use to lookup clients for my app. It works like a type ahead lookup, in its config I have hiddenName and valueField both set to my clientID, I also have the stores idProperty set to the clientID. However when I call getValue on the combo or call form.getValues() it is returning the incorrect id. If there are say 5 "Burnes" in the store and I selct the last one it gets the id from the first one. Its liek tis doing a find on the store to select the id value, and its getting the wrong one.

It grabs the right record on select, but getValue from the field or form level both return the first record thats display value matches in the store. Is this how it should work?

Not sure if this is new to 3.1.1 or if its been around a while.

TopKatz
19 Feb 2010, 5:22 PM
Here is a test case of what I'm seeing:




var combo = new Ext.form.ComboBox({
name:'id',
fieldLabel:'test',
mode:'local',
allowBlank:false,
store:new Ext.data.ArrayStore({
id: 0,
fields: ['id','lastName','firstName'],
data: [[1, 'Smith', 'Joe'], [2, 'Smith', 'Alen'],[3,'Smith','Steve']]
}),
triggerAction:'all',
displayField:'lastName',
valueField:'id',
hiddenName:'id',
itemSelector: "div.search-item",
tpl: new Ext.XTemplate(
'<tpl for="."><div class="search-item">',
'<span><b>First:</b> {firstName}</span><br>',
'<span><b>Last:</b> {lastName}</span><br>',
'<span><b>id:</b> {id}</span><br>',
'</div></tpl>'
),
listeners:{
select:function(c,r,i){
console.log(r.id)
}
}
});

var win = new Ext.Window({
title : 'Win',
constrain:true,
closeAction:'hide',
bodyStyle:'background: #F8F8FF;',
layout:'fit',
modal:true,
height:175,
width:350,
scope:this,
items:[
{
xtype:'form',
id:'form',
items:[
combo
],
buttons:[
{text:'getValue',handler:function(){
console.log(combo.getValue())
}},
{text:'submit',handler:function(){
console.log(Ext.getCmp('form').form.getValues())
}}
]
}

],
listeners:{
hide:function(){
},
scope:this
}
});




I set this up so that you can see in the console that on select the correct item is picked, then by either using the combos getValue method or using the form level collection it retrieves the wrong item in the store.

It is obviously using find in the store on the lastName field.

Was it always this way and I just never noticed it?

I have ways to work around the issue, but would like to know if this is by design.

Katz

tobiu
20 Feb 2010, 4:34 AM
hi topkatz,

it's a known issue and already fixed in svn.
see my bugreport and hotfix-suggestion under:

http://www.extjs.com/forum/showthread.php?t=91252

kind regards,
tobiu

TopKatz
20 Feb 2010, 4:40 AM
Nice, your override did the trick.
Thanks!

TopKatz
20 Feb 2010, 5:31 AM
Just a thought on this that I had but has the dev team thought about storing the index of the selected store value in the combo? That would be a bullet proof way of getting the right record. You could also use it as a initial value to set.

Just a thought.

tobiu
20 Feb 2010, 6:40 AM
the combo has a private var "this.selectedIndex", that stores it.
the problem is the following: you select a value, lets say "john". afterwards you type something else, like "jack". then you click into another field.

the event blur fires. if you have autocomplete on or at least forceSelection, you want the combo to return jack as the selected value.