11

I have ComboBox. When I click on item from expanded list, ComboBox select this item and collapse. If I click on already selected item it also collapsing.

Is there a way to "stop" ComboBox collapsing when user select already selected item?

PS: to be short i want ComboBox to behave like TimeField from http://dev.sencha.com/deploy/ext-4.0.0/examples/themes/index.html

UPDATE

I don't need solutions that dosen't work at least at IE7 and IE8..

shane87
  • 3,090
  • 12
  • 51
  • 65
obenjiro
  • 3,665
  • 7
  • 44
  • 82

3 Answers3

4
var cb = new Ext.form.ComboBox({    
    // here is your local store
    mode: 'local',
    store: new Ext.data.SimpleStore({
        fields: ['id', 'label'],
        data: [
            ['1', 'One'],
            ['2', 'Two']
        ]
    }),    
    listeners: {
        'beforeselect': function (combo, record, index) {
            // prevent collapsing if the same value is selected
            if (record.data.label == combo.getRawValue()) return false;
        }
    }
});
Deniz
  • 793
  • 11
  • 20
3

If you want that behaviour:

Ext.form.field.ComboBox.override({
    onItemClick: Ext.emptyFn
});
Evan Trimboli
  • 29,900
  • 6
  • 45
  • 66
  • You got a tip from one of the developer team and tell him it don't work!? Maybe you should take a closer look at your code. You can just extend or override. To fix it you should post the code that you used instead of the the Ext.emptyFn – sra May 03 '11 at 04:12
  • Wow.. Sorry it works.. the problem was that after i select same content i changed displayValue, so ComboBox was collapsing becose of it, you soulution is actually works... tnx again – obenjiro Jul 11 '11 at 08:49
3

If it's 3.3 you're dealing with, this seems to work:

Ext.form.ComboBox.override({
  onSelect : Ext.form.ComboBox.prototype.onSelect.createInterceptor(function(record) {
    return this.getValue() !== record.data[this.valueField || this.displayField];
  })
});

Tested on Chrome and IE8. It prevents the onSelect function being called if it the current value exactly matches the value you're trying to set.

wombleton
  • 8,336
  • 1
  • 28
  • 30