From c7dd8c517936ca2cfdffa1a5e29372b179c3cf2a Mon Sep 17 00:00:00 2001 From: jdecuyper Date: Tue, 31 Dec 2013 12:01:48 -0600 Subject: [PATCH] Enable nextSearchTerm function for multiple select --- select2.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/select2.js b/select2.js index 67f6b85e..9188d90a 100644 --- a/select2.js +++ b/select2.js @@ -2722,6 +2722,15 @@ the specific language governing permissions and limitations under the Apache Lic this.focusSearch(); + // initializes search's value with nextSearchTerm (if defined by user) + // ignore nextSearchTerm if the dropdown is opened by the user pressing a letter + if(this.search.val() === "") { + if(this.nextSearchTerm != undefined){ + this.search.val(this.nextSearchTerm); + this.search.select(); + } + } + this.updateResults(true); this.search.focus(); this.opts.element.trigger($.Event("select2-open")); @@ -2786,6 +2795,9 @@ the specific language governing permissions and limitations under the Apache Lic this.opts.element.trigger({ type: "selected", val: this.id(data), choice: data }); + // keep track of the search's value before it gets cleared + this.nextSearchTerm = this.opts.nextSearchTerm(data, this.search.val()); + this.clearSearch(); this.updateResults(); @@ -2802,6 +2814,13 @@ the specific language governing permissions and limitations under the Apache Lic // if we reached max selection size repaint the results so choices // are replaced with the max selection reached message this.updateResults(true); + } else { + // initializes search's value with nextSearchTerm and update search result + if(this.nextSearchTerm != undefined){ + this.search.val(this.nextSearchTerm); + this.updateResults(); + this.search.select(); + } } this.positionDropdown(); } else {