From 293bd830b29f0e9eaded8db25fecaa8bfaa72a9a Mon Sep 17 00:00:00 2001 From: Igor Vaynberg Date: Tue, 24 Apr 2012 10:46:21 -0700 Subject: [PATCH] added closeOnSelect option, closes #40 --- select2.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/select2.js b/select2.js index bb76fa20..bafb8da3 100755 --- a/select2.js +++ b/select2.js @@ -1062,6 +1062,9 @@ prepareOpts: function () { var opts = this.parent.prepareOpts.apply(this, arguments); + opts = $.extend({}, { + closeOnSelect: true + }, opts); // TODO validate placeholder is a string if specified @@ -1233,8 +1236,16 @@ onSelect: function (data) { this.addSelectedChoice(data); if (this.select) { this.postprocessResults(); } - this.close(); - this.search.width(10); + + + if (this.opts.closeOnSelect) { + this.close(); + this.search.width(10); + } else { + this.search.width(10); + this.resizeSearch(); + this.alignDropdown(); + } // since its not possible to select an element that has already been // added we do not need to check if this is a new element before firing change