Allow the use of the tab key to select options in combo boxes. Fixes #1251

This commit is contained in:
Surinder Kumar
2016-08-19 16:35:42 +01:00
committed by Dave Page
parent 5690dfda16
commit 4c2020cdc7
3 changed files with 37 additions and 10 deletions

View File

@@ -1851,7 +1851,7 @@
render: function() {
if(this.$sel && this.$sel.select2) {
this.$sel.select2('destroy')
this.$sel.select2('destroy');
}
var field = _.defaults(this.field.toJSON(), this.defaults),
@@ -1916,6 +1916,17 @@
*/
this.$sel = this.$el.find("select").select2(select2Opts);
// Select the highlighted item on Tab press.
if (this.$sel) {
this.$sel.data('select2').on("keypress", function(ev) {
var self = this;
if (ev.which === 9) { // keycode 9 is for TAB key
ev.preventDefault();
self.trigger('results:select', {});
}
});
}
this.updateInvalid();
return this;

View File

@@ -538,7 +538,18 @@
this.delegateEvents();
// Initialize select2 control.
this.$select.select2(select2_opts);
this.$sel = this.$select.select2(select2_opts);
// Select the highlighted item on Tab press.
if (this.$sel) {
this.$sel.data('select2').on("keypress", function(ev) {
var self = this;
if (ev.which === 9) { // keycode 9 is for TAB key
self.trigger('results:select', {});
ev.preventDefault();
}
});
}
return this;
},