Skip to content

Commit 80bda0a

Browse files
committed
Fixed the selectOnClose option
The `selectOnClose` option did not work in production because we were decorating the `dropdownAdapter` instead of the `resultsAdpater` when automatically generating the adapters. This has now been fixed, and the option should work without errors in production. This also adds documentation for the `selectOnClose` option. This closes select2#2953.
1 parent 686f846 commit 80bda0a

8 files changed

Lines changed: 65 additions & 52 deletions

File tree

dist/js/select2.amd.full.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3650,13 +3650,6 @@ define('select2/defaults',[
36503650
);
36513651
}
36523652

3653-
if (options.selectOnClose) {
3654-
options.dropdownAdapter = Utils.Decorate(
3655-
options.dropdownAdapter,
3656-
SelectOnClose
3657-
);
3658-
}
3659-
36603653
options.dropdownAdapter = Utils.Decorate(
36613654
options.dropdownAdapter,
36623655
AttachBody

dist/js/select2.amd.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3650,13 +3650,6 @@ define('select2/defaults',[
36503650
);
36513651
}
36523652

3653-
if (options.selectOnClose) {
3654-
options.dropdownAdapter = Utils.Decorate(
3655-
options.dropdownAdapter,
3656-
SelectOnClose
3657-
);
3658-
}
3659-
36603653
options.dropdownAdapter = Utils.Decorate(
36613654
options.dropdownAdapter,
36623655
AttachBody

dist/js/select2.full.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4088,13 +4088,6 @@ define('select2/defaults',[
40884088
);
40894089
}
40904090

4091-
if (options.selectOnClose) {
4092-
options.dropdownAdapter = Utils.Decorate(
4093-
options.dropdownAdapter,
4094-
SelectOnClose
4095-
);
4096-
}
4097-
40984091
options.dropdownAdapter = Utils.Decorate(
40994092
options.dropdownAdapter,
41004093
AttachBody

dist/js/select2.full.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/select2.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4088,13 +4088,6 @@ define('select2/defaults',[
40884088
);
40894089
}
40904090

4091-
if (options.selectOnClose) {
4092-
options.dropdownAdapter = Utils.Decorate(
4093-
options.dropdownAdapter,
4094-
SelectOnClose
4095-
);
4096-
}
4097-
40984091
options.dropdownAdapter = Utils.Decorate(
40994092
options.dropdownAdapter,
41004093
AttachBody

dist/js/select2.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/options.html

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -688,17 +688,29 @@ <h2 id="dropdown-attachContainer">
688688
it will appear in the same location within the DOM as the rest of Select2.
689689
</p>
690690

691-
<dl class="dl-horizontal">
692-
<dt>Adapter</dt>
693-
<dd>
694-
<code title="select2/dropdown">DropdownAdapter</code>
695-
</dd>
691+
<div class="row">
692+
<div class="col-sm-4">
693+
<dl class="dl-horizontal">
694+
<dt>Adapter</dt>
695+
<dd>
696+
<code title="select2/dropdown">DropdownAdapter</code>
697+
</dd>
696698

697-
<dt>Decorator</dt>
698-
<dd>
699-
<code title="select2/dropdown/attachContainer">AttachContainer</code>
700-
</dd>
701-
</dl>
699+
<dt>Decorator</dt>
700+
<dd>
701+
<code title="select2/dropdown/attachContainer">AttachContainer</code>
702+
</dd>
703+
</dl>
704+
</div>
705+
706+
<div class="col-sm-8">
707+
<div class="alert alert-warning">
708+
<strong>Check your build.</strong> This module is only included in the
709+
<a href="index.html#builds-full" class="alert-link">full builds</a> of
710+
Select2.
711+
</div>
712+
</div>
713+
</div>
702714

703715
<div class="alert alert-info">
704716
<strong>
@@ -734,6 +746,30 @@ <h2 id="dropdown-search">
734746
A search box is added to the top of the dropdown automatically for select
735747
boxes where only a single option can be selected.
736748
</p>
749+
750+
<h2 id="dropdown-select-on-close">
751+
Select the highlighted option on close
752+
</h2>
753+
754+
<p>
755+
When users close the dropdown, the last highlighted option can be
756+
automatically selected. This is commonly used in combination with
757+
<a href="#tags">tagging</a> and <a href="#placeholder">placeholders</a>
758+
and other situations where the user is required to select an option, or
759+
they need to be able to quickly select multiple options.
760+
</p>
761+
762+
<dl class="dl-horizontal">
763+
<dt>Adapter</dt>
764+
<dd>
765+
<code title="select2/results">ResultsAdapter</code>
766+
</dd>
767+
768+
<dt>Decorator</dt>
769+
<dd>
770+
<code title="select2/dropdown/selectOnClose">SelectOnClose</code>
771+
</dd>
772+
</dl>
737773
</section>
738774

739775
<section id="events">
@@ -1053,9 +1089,10 @@ <h1>Backwards compatibility</h1>
10531089
</p>
10541090

10551091
<p>
1056-
<strong>The compatibility modules are only included in the full builds of
1057-
Select2</strong>. These files end in <code>.full.js</code>, and the
1058-
compatibility modules are prefixed with <code>select2/compat</code>.
1092+
<strong>The compatibility modules are only included in the
1093+
<a href="index.html#builds-full" class="alert-link">full builds</a> of
1094+
Select2</strong>. These files end in <code>.full.js</code>, and the
1095+
compatibility modules are prefixed with <code>select2/compat</code>.
10591096
</p>
10601097

10611098
<h2 id="initSelection">
@@ -1064,7 +1101,9 @@ <h2 id="initSelection">
10641101

10651102
<p class="alert alert-warning">
10661103
<a href="announcements-4.0.html#removed-initselection" class="alert-link">Deprecated in Select2 4.0.</a>
1067-
This has been replaced by another option.
1104+
This has been replaced by another option and is only available in the
1105+
<a href="index.html#builds-full" class="alert-link">full builds</a> of
1106+
Select2.
10681107
</p>
10691108

10701109
<p>
@@ -1111,7 +1150,9 @@ <h2 id="query">
11111150

11121151
<p class="alert alert-warning">
11131152
<a href="announcements-4.0.html#query-to-data-adapter" class="alert-link">Deprecated in Select2 4.0.</a>
1114-
This has been replaced by another option.
1153+
This has been replaced by another option and is only available in the
1154+
<a href="index.html#builds-full" class="alert-link">full builds</a> of
1155+
Select2.
11151156
</p>
11161157

11171158
<p>

src/js/select2/defaults.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ define([
128128
HidePlaceholder
129129
);
130130
}
131+
132+
if (options.selectOnClose) {
133+
options.resultsAdapter = Utils.Decorate(
134+
options.resultsAdapter,
135+
SelectOnClose
136+
);
137+
}
131138
}
132139

133140
if (options.dropdownAdapter == null) {
@@ -146,13 +153,6 @@ define([
146153
);
147154
}
148155

149-
if (options.selectOnClose) {
150-
options.dropdownAdapter = Utils.Decorate(
151-
options.dropdownAdapter,
152-
SelectOnClose
153-
);
154-
}
155-
156156
options.dropdownAdapter = Utils.Decorate(
157157
options.dropdownAdapter,
158158
AttachBody

0 commit comments

Comments
 (0)