From 694432d83d412c617a68a857682c3ea593d8c663 Mon Sep 17 00:00:00 2001 From: Igor Vaynberg Date: Mon, 6 May 2013 20:54:01 -0700 Subject: [PATCH] fix fast typing in IE. fixes #949 --- select2.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/select2.js b/select2.js index 49738701..eb7a264e 100644 --- a/select2.js +++ b/select2.js @@ -1716,11 +1716,24 @@ the specific language governing permissions and limitations under the Apache Lic // single opening: function () { + var el, range; this.parent.opening.apply(this, arguments); if (this.showSearchInput !== false) { + // IE appends focusser.val() at the end of field :/ so we manually insert it at the beginning using a range + // all other browsers handle this just fine + this.search.val(this.focusser.val()); } this.search.focus(); + // in IE we have to move the cursor to the end after focussing, otherwise it will be at the beginning and + // new text will appear *before* focusser.val() + el = this.search.get(0); + if (el.createTextRange) { + range = el.createTextRange(); + range.collapse(false); + range.select(); + } + this.focusser.prop("disabled", true).val(""); this.updateResults(true); this.opts.element.trigger($.Event("select2-open"));