From 698fe7b9e187e182f679aa679eb8b0ecb64a846b Mon Sep 17 00:00:00 2001 From: Stretch Date: Wed, 10 Jun 2015 19:18:13 +1000 Subject: [PATCH] Focus is lost when the change event is triggered This closes https://github.com/select2/select2/issues/3332. --- src/js/select2/selection/search.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/js/select2/selection/search.js b/src/js/select2/selection/search.js index be306552..4146e615 100644 --- a/src/js/select2/selection/search.js +++ b/src/js/select2/selection/search.js @@ -128,6 +128,8 @@ define([ }; Search.prototype.update = function (decorated, data) { + var searchHadFocus = this.$search[0] == document.activeElement; + this.$search.attr('placeholder', ''); decorated.call(this, data); @@ -136,6 +138,9 @@ define([ .append(this.$searchContainer); this.resizeSearch(); + if (searchHadFocus) { + this.$search.focus(); + } }; Search.prototype.handleSearch = function () {