Skip to content

Commit ce2204c

Browse files
committed
Code samples for options affecting the dropdown
This is just code samples, most of this still needs readable (non-code) documentation that actually explains what is going on with the options.
1 parent 55aa2c6 commit ce2204c

3 files changed

Lines changed: 50 additions & 0 deletions

File tree

docs/_includes/options/dropdown/filtering.html

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,49 @@ <h3>
77
Can Select2 wait until the user has typed a search term before triggering the request?
88
</h3>
99

10+
<pre class="prettyprint">
11+
$('select').select2({
12+
ajax: {
13+
delay: 250 // wait 250 milliseconds before triggering the request
14+
}
15+
});
16+
</pre>
17+
1018
{% include options/not-written.html %}
1119

1220
<h3>
1321
Select2 is allowing long search terms, can this be prevented?
1422
</h3>
1523

24+
<pre class="prettyprint">
25+
$('select').select2({
26+
maximumInputLength: 20 // only allow terms up to 20 characters long
27+
});
28+
</pre>
29+
1630
{% include options/not-written.html %}
1731

1832
<h3>
1933
I only want the search box if there are enough results
2034
</h3>
2135

36+
<pre class="prettyprint">
37+
$('select').select2({
38+
minimumResultsForSearch: 20 // at least 20 results must be displayed
39+
});
40+
</pre>
41+
42+
{% include options/not-written.html %}
43+
44+
<h3>
45+
How can I permanently hide the search box?
46+
</h3>
47+
48+
<pre class="prettyprint">
49+
$('select').select2({
50+
minimumResultsForSearch: Infinity
51+
});
52+
</pre>
53+
2254
{% include options/not-written.html %}
2355
</section>

docs/_includes/options/dropdown/placement.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ <h3 id="dropdownParent">
1313
Can I pick an element for the dropdown to be appended to?
1414
</h3>
1515

16+
<pre class="prettyprint">
17+
$('select').select2({
18+
dropdownParent: $('#my_amazing_modal')
19+
});
20+
</pre>
21+
1622
{% include options/not-written.html %}
1723

1824
<h3>

docs/_includes/options/dropdown/selections.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,23 @@ <h3>
77
Can I select the highlighted result when the dropdown is closed?
88
</h3>
99

10+
<pre class="prettyprint">
11+
$('select').select2({
12+
selectOnClose: true
13+
});
14+
</pre>
15+
1016
{% include options/not-written.html %}
1117

1218
<h3>
1319
Can I prevent the dropdown from closing when a result is selected?
1420
</h3>
1521

22+
<pre class="prettyprint">
23+
$('select').select2({
24+
closeOnSelect: false
25+
});
26+
</pre>
27+
1628
{% include options/not-written.html %}
1729
</section>

0 commit comments

Comments
 (0)