View Full Version : How to make a Combobox "snap back" to the last valid value?

9 Jun 2009, 3:48 AM

I have a Combobox with editable:true and forceSelection:true. When I type an invalid value and tab away, the Combobox snaps back to the last valid value and the invalid text gets removed. So far, that's fine.

But if I remove the entire text in the input field and tab away then, the Combobox stays empty, while getValue() still returns the last valid value. I have two problems with that:

a) Apparent violation of the forceSelection:true setting - as there is no "empty" option that could be selected, it must not be possible that the Combobox displays an empty text input field after tabbing away.

b) Visible state is different from internal state - while text input field stays empty, getValue() still returns the last valid value, i.e. the user may believe to have "tricked" the Combobox into allowing an empty selection, while in fact the last selected value will be submitted.

As a workaround, I tried something like:

,listeners: {
'blur': function() {
this.setValue( this.getValue() );
}That seems to work as expected, as the Combobox now never appears to have nothing selected when tabbing away, and the visible state always reflects the internal state.

But I wonder if there's a better solution, maybe I just didn't get the right combination of config settings. What I want to do is rather simple:
* force the user to select one of the existing options
* don't allow the field to be left blank
* make use of the auto-complete behaviour

Any help is appreciated.

EDIT: Pls excuse, I've just noticed that I posted in the wrong forum, as I'm using Ext 2.2, not 3.0!

9 Jun 2009, 3:54 AM
allowBlank: false

9 Jun 2009, 4:08 AM
Thank you Animal, but that does not fully do the trick. allowBlank:false marks the field as erroneous when leaving it blank, but it does not force the Combobox to snap back to the last value - you can still leave it blank and just close the options by pressing the trigger button.