Bug 24317: search in language combobox

This commit is contained in:
Julia Radzhabova 2019-07-11 15:24:49 +03:00
parent 32fcfea639
commit 87ab2d0e6d
2 changed files with 57 additions and 1 deletions

View file

@ -85,6 +85,7 @@ define([
menuStyle : '', menuStyle : '',
displayField: 'displayValue', displayField: 'displayValue',
valueField : 'value', valueField : 'value',
search : false,
scrollAlwaysVisible: false scrollAlwaysVisible: false
}, },
@ -119,6 +120,7 @@ define([
this.store = me.options.store || new Common.UI.ComboBoxStore(); this.store = me.options.store || new Common.UI.ComboBoxStore();
this.displayField = me.options.displayField; this.displayField = me.options.displayField;
this.valueField = me.options.valueField; this.valueField = me.options.valueField;
this.search = me.options.search;
this.scrollAlwaysVisible = me.options.scrollAlwaysVisible; this.scrollAlwaysVisible = me.options.scrollAlwaysVisible;
me.rendered = me.options.rendered || false; me.rendered = me.options.rendered || false;
@ -295,12 +297,14 @@ define([
if (itemTop < 0 || itemTop + itemHeight > listHeight) { if (itemTop < 0 || itemTop + itemHeight > listHeight) {
$list.scrollTop($list.scrollTop() + itemTop + itemHeight - (listHeight/2)); $list.scrollTop($list.scrollTop() + itemTop + itemHeight - (listHeight/2));
} }
setTimeout(function(){$selected.find('a').focus();}, 1);
} }
if (this.scroller) if (this.scroller)
this.scroller.update({alwaysVisibleY: this.scrollAlwaysVisible}); this.scroller.update({alwaysVisibleY: this.scrollAlwaysVisible});
this.trigger('show:after', this, e); this.trigger('show:after', this, e);
this._search = {};
}, },
onBeforeHideMenu: function(e) { onBeforeHideMenu: function(e) {
@ -332,6 +336,57 @@ define([
this.closeMenu(); this.closeMenu();
this.onAfterHideMenu(e); this.onAfterHideMenu(e);
return false; return false;
} else if (this.search && e.keyCode > 64 && e.keyCode < 91 && e.key){
var me = this;
clearTimeout(this._search.timer);
this._search.timer = setTimeout(function () { me._search = {}; }, 1000);
(!this._search.text) && (this._search.text = '');
(!this._search.char) && (this._search.char = e.key);
(this._search.char !== e.key) && (this._search.full = true);
this._search.text += e.key;
if (this._search.index===undefined) {
var $items = this.cmpEl.find('ul > li').find('> a');
this._search.index = $items.index($items.filter(':focus'));
}
this.selectCandidate();
}
},
selectCandidate: function() {
var index = this._search.index || 0,
re = new RegExp('^' + ((this._search.full) ? this._search.text : this._search.char), 'i'),
itemCandidate, idxCandidate;
for (var i=0; i<this.store.length; i++) {
var item = this.store.at(i);
if (re.test(item.get(this.displayField))) {
if (!itemCandidate) {
itemCandidate = item;
idxCandidate = i;
}
if (this._search.full && i==index || i>index) {
itemCandidate = item;
idxCandidate = i;
break;
}
}
}
if (itemCandidate) {
this._search.index = idxCandidate;
var item = $('#' + itemCandidate.get('id') + ' a', $(this.el));
if (this.scroller) {
this.scroller.update({alwaysVisibleY: this.scrollAlwaysVisible});
var $list = $(this.el).find('ul');
var itemTop = item.position().top,
itemHeight = item.height(),
listHeight = $list.height();
if (itemTop < 0 || itemTop + itemHeight > listHeight) {
$list.scrollTop($list.scrollTop() + itemTop + itemHeight - (listHeight/2));
}
}
item.focus();
} }
}, },

View file

@ -104,7 +104,8 @@ define([
'</ul>', '</ul>',
'</span>' '</span>'
].join('')), ].join('')),
data: this.options.languages data: this.options.languages,
search: true
}); });
if (this.cmbLanguage.scroller) this.cmbLanguage.scroller.update({alwaysVisibleY: true}); if (this.cmbLanguage.scroller) this.cmbLanguage.scroller.update({alwaysVisibleY: true});