PDA

View Full Version : GXT ComboBox with Duplicate Display Values



vijay_v11
10 May 2010, 2:01 AM
I am using GXT version 2.1.1.
GXT ComboBox with Duplicate Display Values behaves weirdly. Whenever any value from the combobox is selected, getValue() or getSelection() always returns the first matching element from the list.

For example if the list contains the following elements -
Hidden Value - Display Value
1 "Value 1"
2 "Value 2",
3 "Value 3",
4 "Value 1"

Even after selecting the fourth element "Value 1" from the list, getValue() returns the first element from the list i.e. Hidden Value '1'.

Guess this is due to the foll code snippet:

Class: com.extjs.gxt.ui.client.widget.form.ListModelPropertyEditor
Method:
public Data convertStringValue(String value) {
for (Data d : models) {
Object val = d.get(displayProperty);
if (value.equals(val != null ? val.toString() : null)) {
return d;
}
}
return null;
}

This method is called from getValue() of Field class which is parent of ComboBox class. This compares the display value instead of comparing the hidden value.

Is there any api which returns elements by comparing the hidden value? If not then this has to be corrected.

sven
10 May 2010, 2:03 AM
This is by design. It does not make much sense to show the exact same value to the user but in the end, they are different.

vijay_v11
10 May 2010, 2:10 AM
Sven can you please elaborate on your point?

sven
10 May 2010, 2:16 AM
Imagine you selectbox with two options, you name both "Option". On stands for "yes" the other one for "no". How the user should know htis if he reads two times the same text? It does not make sense to have two times the same text and represent two different values.

vijay_v11
10 May 2010, 2:48 AM
Ok. Got your point. So in that case it would be useful if the combo store starts accepting Set instead of List; so as to avoid duplicate data upfront.

manjushrestha
15 Jun 2010, 7:11 AM
I am having same issue. I have a combobox that display a file name, but the file can be located in different folders.
Example:
ID File Name Location
1 test c:\dev
2 test c:\test
3 test c:\prod
Using template, when the users click the dropdown list, they can see the file name and the location. However whenever the users select a file name, it will always select the first file name.

Any suggestion????

vijay_v11
15 Jun 2010, 7:24 AM
This is by design. A combobox displaying multiple similar values would only end up confusing the end user. It is better to avoid such scenarios by making all the display values unique. The logic to make it unique could be business-driven.

Jeff Miner
9 Nov 2010, 12:10 PM
This is, then, a bad design - think about templated combos - they can display the same primary value with multiple distinguishing features in secondary data.

Possibly worse, it indicates that undeneath, there's a text search of the store on select - why?

Jeff Miner
9 Nov 2010, 12:11 PM
It may not make much sense, but since they are, in fact, different the combo should be capable of distinguishing them

nullifier
23 Jan 2011, 8:02 PM
I have to agree, the combo box should have a way of determining which item(s) in the list has been selected by the user, regardless of what model data is behind the combo box. There should simply be an internal index system that can be accessed by the developer. Perhaps add another method to the SelectionChagedListener that gives the selected index,.

Call me old school, but I think It IS intuitive (as a Google search on "GXT combo box only selects first value" demonstrates), that a web developer would write logic (a presenter) to query the combo box's selected index (the display) and retrieve the associated model data (model).

Jeff Miner
26 Jan 2011, 9:12 PM
Yes, I think manjushrestha's example above shows a perfect use-case for this.

it's really dumb that selecting doesn't select, but searches - bad API and bad performance-wise