Aug 22, 2014, 6:14 PM
[CLOSED] Multiple items with same value on combobox
I have a custom control that inherits from combobox. The problem is that it must be able to store different items with the same value and when this happens, when the user chooses any item with the same value the first item with this value always gets selected.
Let?s say the store has these fields: _Value, _Display, Company, Branch
_Value is defined as ValueField, and _Display as the DisplayField.
And i load the combobox with these values:
[_Value][_Display][Company][Branch]
[001][001 - Rio de Janeiro][000][001]
[002][002 - Goi?s][000][002]
[001][001 - Filial 1][001][001]
[002][002 - Filial 2][001][002]
[XPTO][XPTO - Filial 00][KLH0][XPTO]
The user can see all the values fine. But if he selects the row "[001][001 - Filial 1][001][001]", the display shown is "001 - Rio de Janeiro", from the row "[001][001 - Rio de Janeiro][000][001]", which is the first row with value "001".
To solve this i've tried to override the method "findRecord" in many ways. The one that almost worked was this, where instead of finding the item only by it's value, i compare all of the rows:
Any hint on how to make the combobox select the item the user chooses, instead of getting the item by (first) value? I'm stuck with this one..
Let?s say the store has these fields: _Value, _Display, Company, Branch
_Value is defined as ValueField, and _Display as the DisplayField.
And i load the combobox with these values:
[_Value][_Display][Company][Branch]
[001][001 - Rio de Janeiro][000][001]
[002][002 - Goi?s][000][002]
[001][001 - Filial 1][001][001]
[002][002 - Filial 2][001][002]
[XPTO][XPTO - Filial 00][KLH0][XPTO]
The user can see all the values fine. But if he selects the row "[001][001 - Filial 1][001][001]", the display shown is "001 - Rio de Janeiro", from the row "[001][001 - Rio de Janeiro][000][001]", which is the first row with value "001".
To solve this i've tried to override the method "findRecord" in many ways. The one that almost worked was this, where instead of finding the item only by it's value, i compare all of the rows:
findRecord: function (prop, value) {
var record;
var thisObj = this;
if (this.store.getCount() > 0) {
this.store.each(function (r) {
var fitsValues = true;
var selectedIndexData = thisObj.getStore().data.items[thisObj.selectedIndex].data;
for (var i = 0; i < thisObj.getStore().fields.keys.length; i++) {
var currentField = thisObj.getStore().fields.keys[i];
if (r.data[currentField] != selectedIndexData[currentField]) {
fitsValues = false;
}
}
if (fitsValues && r.data[prop] == value) {
record = r;
return false;
}
});
}
return record;
},
It works perfectly when the user clicks on the combobox trigger and selects an item with the mouse. But when he types some filter text and selects an item with the keyboard, it won't work fine. The method findRecord is called many times, it's hard even to debug and figure out what's going on. I guess the problem is with the selectedIndex, that doesn't behave as well when in filter mode as when the user selects an item with the mouse.Any hint on how to make the combobox select the item the user chooses, instead of getting the item by (first) value? I'm stuck with this one..
Last edited by Daniil; Sep 05, 2014 at 8:04 AM.
Reason: [CLOSED]