View Full Version : [2.0.1] wrong value from combobox

3 Aug 2009, 6:04 AM
i looked at this example:

[CLOSED] Combo Box: Selection doesn't get changed for items with same name

and find out that the implementation of getValue is not as expected:

public D getValue() {
if (!initialized) {
return value;
if (store != null) {


D v = super.getValue();
// a value was set directly and there is not a
// matching value in the drop down list
String rv = getRawValue();
boolean empty = rv == null || rv.equals("");
if (rendered && !empty && v == null && value != null && !forceSelection) {
return value;
return super.getValue();

it should return exactly the selected item (which is already in the this.value field).

so i dont understand why the display value is need to compare to the values in the store if the selected value is already there and with this search the wrong item is returned.

compared to ExtJS 3.0 behavoir of the combobox i see:

* Returns the currently selected field value or empty string if no value is set.
* @return {String} value The selected value
getValue : function(){
return Ext.isDefined(this.value) ? this.value : '';
return Ext.form.ComboBox.superclass.getValue.call(this);

related threads:
[CLOSED] [1.24] ComboBox value selection

getValue in ComboBox not working properly when raw value modified in grid

3 Aug 2009, 6:07 AM
Moved this to the help forum. We cant change the hole way the method works. It was there since the beginning. Also we cant just return "this.value". This will brake every app.

Please only use the bugforum for real bugs and than post according to the bugforum guidelines.

3 Aug 2009, 6:29 AM
but i think its a bug if the value which returns is not the value from the row which i selected.
the same all other thinking in the related threads

but i dont understand what breaks every app if the combobox works like expected?

3 Aug 2009, 6:31 AM
You select value X from the list.

Than you go over and type an own entry in the combobox.

getValue still returns X but that is not the value.

3 Aug 2009, 8:21 AM
also is there a selectedItem which is filled by this code:

selectedItem = listView.getSelectionModel().getSelectedItem();

so you have the clicked item. in case of typing in some values then you need more decitions. and then i agree with you that in this case you should lookup the value in the store.

in case of typing your own value in the list, then you can set the selectedItem to null.

but the main rule should not break: the selected Model should be returned if i click a row independend how its rendered or the text display.

3 Aug 2009, 8:25 AM
but the main rule should not break: the selected Model should be returned if i click a row independend how its rendered or the text display.

This is wrong. You may select something. But than you rethink your decision and enter some own value on the combo. Than the selected value should not be returned. Returning that value is bad.

If you need this behaviour you can easily extend combobox. We are not going to change this.

3 Aug 2009, 8:29 AM
if you look at ExtJS ComboBox:


A ComboBox works in a similar manner to a traditional HTML <select> field.Testcase

Please look at this test case with ExtJS and plain html select.

(just copy this file into your extjs 3.0 examples folder: examples\form (where also the combos.html is)

look there are 2 arizonas

['AZ', 'Arizona', 'The Grand Canyon State'],
['AX', 'Arizona', 'The Grand Canyon State'],

if you click any of the arizonas then look at the different abbr value: AZ vs. AX

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Combo Boxes</title>
<link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="../../resources/css/xtheme-gray.css" />
<script type="text/javascript" src="../../adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../../ext-all.js"></script>
<link rel="stylesheet" type="text/css" href="combos.css" />
<link rel="stylesheet" type="text/css" href="../shared/examples.css" />
<style type="text/css">
p { width:650px; }
<script type="text/javascript" >

Ext.exampledata.states = [
['AL', 'Alabama', 'The Heart of Dixie'],
['AK', 'Alaska', 'The Land of the Midnight Sun'],
['AZ', 'Arizona', 'The Grand Canyon State'],
['AX', 'Arizona', 'The Grand Canyon State'],
['AR', 'Arkansas', 'The Natural State'],
['CA', 'California', 'The Golden State'],
['CO', 'Colorado', 'The Mountain State'],
['CT', 'Connecticut', 'The Constitution State']


// simple array store
var store = new Ext.data.ArrayStore({
fields: ['abbr', 'state', 'nick'],
data : Ext.exampledata.states // from states.js

var combo = new Ext.form.ComboBox({
tpl: '<tpl for="."><div ext:qtip="[{abbr}]{state}. {nick}" class="x-combo-list-item">{state}</div></tpl>',
store: store,
typeAhead: true,
mode: 'local',
forceSelection: true,
triggerAction: 'all',
emptyText:'Select a state...',
applyTo: 'local-states'

combo.on('select', function(e){ Ext.Msg.alert("Abbr",combo.getValue()); });


<h1>Combo Box with ExtJS</h1>

<input type="text" id="local-states" size="20"/>
<h1>Original HTML select box</h1>
<select name="state-orig" onChange="alert('Value: '+this.value+'\nNamePart: '+this.options[this.selectedIndex].text);">
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AX">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>

3 Aug 2009, 8:52 AM
Also that was explained in the bugreport you linked. Define your own ListModelPropertyEditor that checks for more fields than just the displayfield.

Also note that GXT is not Ext JS. They are only looking familiar

26 Aug 2009, 6:01 AM
if the ListModelPropertyEditor should give me also the selectedItem then it can be possible to make it this way.