最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ExtJs 4, How to prevent xtype: 'combo' from collapsing when already selected item clicked? - Stack

programmeradmin3浏览0评论

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 .0.0/examples/themes/index.html

UPDATE

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

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./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..

Share Improve this question edited May 5, 2011 at 16:44 shane87 3,12013 gold badges52 silver badges65 bronze badges asked Apr 27, 2011 at 10:44 obenjiroobenjiro 3,7607 gold badges49 silver badges82 bronze badges 1
  • 1 if you won't know the answer then at least vote for it, so other could find this question... – obenjiro Commented Apr 27, 2011 at 11:17
Add a ment  | 

3 Answers 3

Reset to default 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 (bo, record, index) {
            // prevent collapsing if the same value is selected
            if (record.data.label == bo.getRawValue()) return false;
        }
    }
});

If you want that behaviour:

Ext.form.field.ComboBox.override({
    onItemClick: Ext.emptyFn
});

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论