Skip to content
This repository

Added closeOnSelect parameter for single value selects2 widgets #597

Closed
wants to merge 1 commit into from

2 participants

Igor Vaynberg

In my usage scenario I wanted to append a single choice select2 widget to a list of items that require complex formatting, however as multiple items can be added it would be nice to be able to use closeOnSelect. Currently it is not supported on single choice widgets.

Igor Vaynberg
Owner

if you want to add multiple items doesnt it make sense to use the multiselect? also please rebase your commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Nov 21, 2012
Nils Kaiser Added closeOnSelect parameter for single value selects2 widgets c7a7504
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 8 additions and 3 deletions. Show diff stats Hide diff stats

  1. +8 3 select2.js
11 select2.js
@@ -1337,7 +1337,9 @@ the specific language governing permissions and limitations under the Apache Lic
1337 1337 highlighted=this.results.find(".select2-highlighted").not(".select2-disabled"),
1338 1338 data = highlighted.closest('.select2-result-selectable').data("select2-data");
1339 1339 if (data) {
1340   - highlighted.addClass("select2-disabled");
  1340 + if (this.opts.multiple || this.opts.closeOnSelect) {
  1341 + highlighted.addClass("select2-disabled");
  1342 + }
1341 1343 this.highlight(index);
1342 1344 this.onSelect(data);
1343 1345 }
@@ -1694,8 +1696,11 @@ the specific language governing permissions and limitations under the Apache Lic
1694 1696
1695 1697 this.opts.element.val(this.id(data));
1696 1698 this.updateSelection(data);
1697   - this.close();
1698   - this.selection.focus();
  1699 +
  1700 + if (this.opts.closeOnSelect) {
  1701 + this.close();
  1702 + this.selection.focus();
  1703 + }
1699 1704
1700 1705 if (!equal(old, this.id(data))) { this.triggerChange(); }
1701 1706 },

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.