1
0
mirror of synced 2025-03-10 14:46:10 +03:00

Automatically open search when typing

This fixes an issue where the dropdown would not automatically
open when something was typed in the search box on a multiple
select.  This was most noticeable when the dropdown closed and
the search box was focused and the user started to type, as the
text would appear in the search box, queries would be sent out to
retrieve results, but the dropdown would not be opened to display
the results.

This also fixes an issue introduced in a recent commit where search
queries would be sent out twice on modern browsers that supported
both the `keyup` and `input` event.  The `keyup` event is now
properly debounced for these browsers and the queries are only
going out once.

This closes https://github.com/select2/select2/issues/3036.
This commit is contained in:
Kevin Brown 2015-03-01 21:01:11 -05:00
parent 017c201094
commit 94875679f8
8 changed files with 35 additions and 15 deletions

View File

@ -1318,10 +1318,10 @@ define('select2/selection/search',[
// both the `keyup` and `input` events.
this.$selection.on('input', '.select2-search--inline', function (evt) {
// Unbind the duplicated `keyup` event
$(this).off('keyup');
self.$selection.off('keyup.search');
});
this.$selection.on('keyup input', '.select2-search--inline',
this.$selection.on('keyup.search input', '.select2-search--inline',
function (evt) {
self.handleSearch(evt);
});
@ -4471,6 +4471,10 @@ define('select2/core',[
});
this.on('query', function (params) {
if (!self.isOpen()) {
self.trigger('open');
}
this.data.query(params, function (data) {
self.trigger('results:all', {
data: data,

View File

@ -1318,10 +1318,10 @@ define('select2/selection/search',[
// both the `keyup` and `input` events.
this.$selection.on('input', '.select2-search--inline', function (evt) {
// Unbind the duplicated `keyup` event
$(this).off('keyup');
self.$selection.off('keyup.search');
});
this.$selection.on('keyup input', '.select2-search--inline',
this.$selection.on('keyup.search input', '.select2-search--inline',
function (evt) {
self.handleSearch(evt);
});
@ -4471,6 +4471,10 @@ define('select2/core',[
});
this.on('query', function (params) {
if (!self.isOpen()) {
self.trigger('open');
}
this.data.query(params, function (data) {
self.trigger('results:all', {
data: data,

View File

@ -1757,10 +1757,10 @@ define('select2/selection/search',[
// both the `keyup` and `input` events.
this.$selection.on('input', '.select2-search--inline', function (evt) {
// Unbind the duplicated `keyup` event
$(this).off('keyup');
self.$selection.off('keyup.search');
});
this.$selection.on('keyup input', '.select2-search--inline',
this.$selection.on('keyup.search input', '.select2-search--inline',
function (evt) {
self.handleSearch(evt);
});
@ -4910,6 +4910,10 @@ define('select2/core',[
});
this.on('query', function (params) {
if (!self.isOpen()) {
self.trigger('open');
}
this.data.query(params, function (data) {
self.trigger('results:all', {
data: data,

File diff suppressed because one or more lines are too long

8
dist/js/select2.js vendored
View File

@ -1757,10 +1757,10 @@ define('select2/selection/search',[
// both the `keyup` and `input` events.
this.$selection.on('input', '.select2-search--inline', function (evt) {
// Unbind the duplicated `keyup` event
$(this).off('keyup');
self.$selection.off('keyup.search');
});
this.$selection.on('keyup input', '.select2-search--inline',
this.$selection.on('keyup.search input', '.select2-search--inline',
function (evt) {
self.handleSearch(evt);
});
@ -4910,6 +4910,10 @@ define('select2/core',[
});
this.on('query', function (params) {
if (!self.isOpen()) {
self.trigger('open');
}
this.data.query(params, function (data) {
self.trigger('results:all', {
data: data,

File diff suppressed because one or more lines are too long

View File

@ -272,6 +272,10 @@ define([
});
this.on('query', function (params) {
if (!self.isOpen()) {
self.trigger('open');
}
this.data.query(params, function (data) {
self.trigger('results:all', {
data: data,

View File

@ -84,10 +84,10 @@ define([
// both the `keyup` and `input` events.
this.$selection.on('input', '.select2-search--inline', function (evt) {
// Unbind the duplicated `keyup` event
$(this).off('keyup');
self.$selection.off('keyup.search');
});
this.$selection.on('keyup input', '.select2-search--inline',
this.$selection.on('keyup.search input', '.select2-search--inline',
function (evt) {
self.handleSearch(evt);
});