PDA

View Full Version : [FIXED-1033] ComboBox reports incorrect value when non-unique display fields are used



dlouwers
8 Jun 2010, 4:54 AM
Ext version tested:


Ext 3.2.1



Adapter used:


jquery



css used:


only default ext-all.css





Browser versions tested against:


FF 3.6.3 (firebug 1.5.4 installed)
Safari 4.0.5



Operating System:


OSX 10.6



Description:


When a ComboBox is bound to data that has non-unique field values the selected record is changed to the first record with the same display field value



Test Case:



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title id='title'>Title</title>

<!-- ** CSS ** -->
<!-- base library -->
<link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css" />

<!-- overrides to base library -->


<!-- ** Javascript ** -->
<!-- base library -->
<script type="text/javascript" src="../../adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../../ext-all-debug.js"></script>


<!-- overrides to base library -->

<!-- extensions -->

<!-- page specific -->

<script type="text/javascript">
Ext.BLANK_IMAGE_URL = '../../resources/images/default/s.gif';

Ext.onReady(function(){

var store = new Ext.data.ArrayStore({
storeId: 'testStore',
idIndex: 0,
fields: [
{ name: 'id', type: 'integer' },
{ name: 'name', type: 'string' }
],
data: [
[1, 'Dummy'],
[2, 'Example'],
[3, 'Example'],
[4, 'Dummy 2']
]
});
var formpanel = new Ext.form.FormPanel({
items: [{
xtype: 'combo',
ref: 'myCombo',
store: store,
valueField: 'id',
displayField: 'name',
mode: 'local',
listeners: {
select: function(combo, record, index) {
formpanel.correctValue = formpanel.myCombo.value;
},
scope: this
}
}],
buttons: [{
text: 'Report',
handler: function(button, event) {
alert('value is ' + formpanel.myCombo.value + ' and should be ' + formpanel.correctValue);
}
}]
});
formpanel.render(Ext.getBody());

}); //end onReady
</script>

</head>
<body>
</body>
</html>
Steps to reproduce the problem:


Select the second item titled 'Example' from the combo
Hit the report button



The result that was expected:


"Value is 3 and should be 3"



The result that occurs instead:


"Value is 2 and should be 3"



Debugging already done:


none



Workaround:


Store the combobox value upon selecting and #setValue to this stored value when needed again

Condor
10 Jun 2010, 1:57 AM
Reported before (http://www.extjs.com/forum/showthread.php?85244-CLOSED-Combo-changes-value-onBlur-when-selected-record-has-quot-doppelgangers-quot) (but report was closed).

dlouwers
10 Jun 2010, 3:20 AM
Hi,

Thanks, naturally did a search but that one didn't come up. So what is the take on this one? Is the report closed because it has been fixed and the fix has been staged for the next release or has it been dubbed invalid for some reason? Cannot get this info from the linked post.

Thanks,

Dirk Louwers

Condor
10 Jun 2010, 5:23 AM
No, it has not been fixed and I don't know the reason the development team closed the other report.

ps. For Ext 3.2 the override would be:

Ext.override(Ext.form.ComboBox, {
assertValue : function(){
var val = this.getRawValue(),
rec;
if(this.valueField && Ext.isDefined(this.value)){
rec = this.findRecord(this.valueField, this.value);
}
if(!rec || rec.get(this.displayField) != val){
rec = this.findRecord(this.displayField, val);
}
if(!rec && this.forceSelection){
if(val.length > 0 && val != this.emptyText){
this.el.dom.value = Ext.value(this.lastSelectionText, '');
this.applyEmptyText();
}else{
this.clearValue();
}
}else{
if(rec && this.valueField){
val = rec.get(this.valueField/* || this.displayField*/);
if (/*val == rec.get(this.displayField) &&*/ this.value == val /*rec.get(this.valueField)*/){
return;
}
}
this.setValue(val);
}
}
});

dlouwers
10 Jun 2010, 7:32 AM
Will I need to submit this bug elsewhere or will it automatically be picked up by a developer if they think it desirable?

jamie.nicholson
8 Nov 2010, 10:15 AM
Also found this to be an issue, was a real head scratcher, until I went source diving into ExtJS source code and came up with a similar override to Condor.

sdrew
10 Nov 2010, 9:26 AM
Another vote for a official fix.

I had an combo with a nice tpl: that shows various levels and under levels the display name maybe same as another. The valueField had a unique number so the combo should work with that.

Thanks to Condor for the override, works great.

meroy
11 Nov 2010, 9:07 PM
This has been fixed in SVN for 3.3.x.

saddanand
11 Nov 2010, 10:33 PM
Hi again, how to disable the forward and backward month selection in datefield..... based on a condtion....

Many Thanks.....