From ad21d01693fc66469c2ee8a76f56cd8f1ef01ac8 Mon Sep 17 00:00:00 2001 From: Lee Boynton Date: Fri, 28 Mar 2014 14:46:41 +0000 Subject: [PATCH] Check if search input should be focussed when opening --- select2.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/select2.js b/select2.js index ea5c902b..ffe6b64b 100644 --- a/select2.js +++ b/select2.js @@ -1915,17 +1915,19 @@ the specific language governing permissions and limitations under the Apache Lic this.search.val(this.focusser.val()); } - this.search.focus(); - // 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(); - } else if (el.setSelectionRange) { - len = this.search.val().length; - el.setSelectionRange(len, len); + if (this.opts.shouldFocusInput(this)) { + this.search.focus(); + // 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(); + } else if (el.setSelectionRange) { + len = this.search.val().length; + el.setSelectionRange(len, len); + } } // initializes search's value with nextSearchTerm (if defined by user)