From 47064b24837492b74ed65c3095414d77123e5cbe Mon Sep 17 00:00:00 2001 From: Igor Vaynberg Date: Thu, 7 Jun 2012 23:09:51 -0700 Subject: [PATCH] tweak to issue #85 do not highlight items based on keypresses --- select2.css | 2 +- select2.js | 26 ++++++-------------------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/select2.css b/select2.css index 457e65c4..e9bdce7a 100755 --- a/select2.css +++ b/select2.css @@ -144,7 +144,7 @@ Version: @@ver@@ Timestamp: @@timestamp@@ padding-right: 4px; } -.select2-container .select2-hide-search { +.select2-container .select2-search-hidden { display: block; position: absolute; left: -10000px; diff --git a/select2.js b/select2.js index 1e6050aa..25ec123c 100755 --- a/select2.js +++ b/select2.js @@ -712,6 +712,11 @@ updateResults: function (initial) { var search = this.search, results = this.results, opts = this.opts, self=this; + // if the search is currently hidden we do not alter the results + if (initial !== true && this.showSearchInput === false) { + return; + } + search.addClass("select2-active"); function render(html) { @@ -735,25 +740,6 @@ var parts = [], // html parts def; // default choice - // If we aren't showing the search input, do not filter items - // but do highlight an item matching current search - if(initial !== true && !this.showSearchInput){ - if(data.results.length > 0){ - var key = data.results[0].id, - self = this; - this.results.find("li").each(function(i, li){ - if($(li).data("select2-data").id == key){ - self.highlight(i); - return false; - } - }); - } else { - // if the search doesn't match, reset so user can search again - search.val(""); - } - return; - } - // create a default choice and prepend it to the list if (this.opts.createSearchChoice && search.val() !== "") { def = this.opts.createSearchChoice.call(null, search.val(), data.results); @@ -1042,7 +1028,7 @@ if (initial === true) { showSearchInput = this.showSearchInput = data.results.length >= this.opts.minimumResultsForSearch; - this.search.parent()[showSearchInput ? "removeClass" : "addClass"]("select2-hide-search"); + this.container.find(".select2-search")[showSearchInput ? "removeClass" : "addClass"]("select2-search-hidden"); //add "select2-with-searchbox" to the container if search box is shown this.container[showSearchInput ? "addClass" : "removeClass"]("select2-with-searchbox");