extJs: Combobox .getValue oddity
At least in extJs version 2.2.1 (the version baked into Coolite v0.8), the getValue function on the Ext.form.ComboBox appears to be thus:
function()
{
if (this.valueField&&this.forceSelection)
{
return typeof this.value!="undefined"?this.value:"";
}
else
{
return Ext.form.ComboBox.superclass.getValue.call(this);
}
}
Of interest is the fact that differing code-paths are taken based on the "forceSelection" property. If it's set (i.e. thou shalt choose something from this combo and not enter free-text), then the .value property is used as the return value of the call to getValue, otherwise a call is made to superclass.getValue, which returns something quite entirely different!
Instead of, as expected, returning the "key" value, it returns the displayed value. This is thanks to superclass.getValue being defined as:
function()
{
if (!this.rendered)
{
return this.value;
}
var v=this.el.getValue();
if (v===this.emptyText || v===undefined)
{
v='';
}
return v;
}
Whilst I've logged this as an "oddity", it is (seemingly) "by-design" as the combo-box allows for user-entered values, which is what the "forceSelection" code-branch causes. That said, I firmly believe that if the "selected value" is one that has been chosen from the contained items, then getValue should return in the same way as it does with forceSelection being false.