You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/_includes/options-new/core/amd-support.html
+23-2Lines changed: 23 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -2,12 +2,33 @@
2
2
<h2id="amd">
3
3
Can I use Select2 with my AMD or CommonJS loader?
4
4
</h2>
5
-
5
+
6
+
<p>
7
+
Yes, Select2 should work with most AMD or CommonJS loaders without any issues.
8
+
</p>
9
+
6
10
<h3>
7
11
How do I tell Select2 where to look for modules?
8
12
</h3>
9
-
13
+
14
+
<p>
15
+
For most AMD and CommonJS setups, the location of the data files used by Select2 will be automatically determined and handled without you needing to do anything.
16
+
</p>
17
+
18
+
<p>
19
+
If you are using Select2 in a build environment where preexisting module names are changed during a build step, Select2 may not be able to find optional dependencies or language files. You can manually set the prefixes to use for these files using the <code>amdBase</code> and <code>amdLanugageBase</code> options.
Select2 is being placed before jQuery in my JavaScript file
12
29
</h3>
30
+
31
+
<p>
32
+
Due to a bug in older versions of the r.js build tool, Select2 was sometimes placed before jQuery in then compiled build file. Because of this, Select2 will trigger an error because it won't be able to find or load jQuery.
Copy file name to clipboardExpand all lines: docs/_includes/options-new/data/ajax.html
+78Lines changed: 78 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -3,10 +3,18 @@ <h2 id="ajax">
3
3
Can Select2 be connected to a remote data source?
4
4
</h2>
5
5
6
+
<p>
7
+
Select2 supports connecting to a remote data source using the <code>ajax</code> option.
8
+
</p>
9
+
6
10
<h3>
7
11
How can I set the initially selected options when using AJAX?
8
12
</h3>
9
13
14
+
<p>
15
+
You can refer to the following Stack Overflow answer if you want to set the initial value for AJAX requests: <ahref="http://stackoverflow.com/q/30316586/359284#30328989">Select2 4.0.0 initial value with AJAX</a>
16
+
</p>
17
+
10
18
<h3>
11
19
What should the results returned to Select2 look like?
12
20
</h3>
@@ -15,15 +23,85 @@ <h3>
15
23
Is there a way to modify the response before passing it back to Select2?
16
24
</h3>
17
25
26
+
<p>
27
+
You can use the <code>ajax.processResults</code> option to modify the data returned from the server before passing it to Select2.
28
+
</p>
29
+
30
+
<preclass="prettyprint">
31
+
$('select').select2({
32
+
ajax: {
33
+
url: '/example/api',
34
+
processResults: function (data) {
35
+
return {
36
+
results: data.items
37
+
};
38
+
}
39
+
}
40
+
});
41
+
</pre>
42
+
18
43
<h3>
19
44
A request is being triggered on every key stroke, can I delay this?
20
45
</h3>
21
46
47
+
<p>
48
+
By default, Select2 will trigger a new AJAX request whenever the user changes their search term. You can set a time limit for debouncing requests using the <code>ajax.delay</code> option.
49
+
</p>
50
+
51
+
<preclass="prettyprint">
52
+
$('select').select2({
53
+
ajax: {
54
+
url: '/example/api',
55
+
delay: 250
56
+
}
57
+
});
58
+
</pre>
59
+
60
+
<p>
61
+
This will tell Select2 to wait 250 milliseconds before sending the request out to your API.
62
+
</p>
63
+
22
64
<h3>
23
65
I want to add more query parameters to the request, where can this be done?
24
66
</h3>
25
67
68
+
<p>
69
+
By default, Select2 will send the query term as well as the pagination data as query parameters in requests. You can override the data that is sent to your API, or change any of the query paramters, by overriding the <code>ajax.data</codE> option.
70
+
</p>
71
+
72
+
<preclass="prettyprint">
73
+
$('select').select2({
74
+
ajax: {
75
+
data: function (params) {
76
+
var query = {
77
+
search: params.term,
78
+
page: params.page
79
+
}
80
+
81
+
// Query paramters will be ?search=[term]&page=[page]
82
+
return query;
83
+
}
84
+
}
85
+
});
86
+
</pre>
87
+
26
88
<h3>
27
89
Can an AJAX plugin other than <code>jQuery.ajax</code> be used?
28
90
</h3>
91
+
92
+
<p>
93
+
Select2 uses the transport method defined in <code>ajax.transport</code> to send requests to your API. By default, this transport method is <code>jQuery.ajax</code> but this can be changed.
94
+
</p>
95
+
96
+
<preclass="prettyprint">
97
+
$('select').select2({
98
+
ajax: {
99
+
transport: function (params, success, failure) {
100
+
var request = new AjaxRequest(params.url, params);
Copy file name to clipboardExpand all lines: docs/_includes/options-new/data/array.html
+24-8Lines changed: 24 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -2,36 +2,52 @@
2
2
<h2id="data">
3
3
Can I load data into Select2 using an array?
4
4
</h2>
5
-
5
+
6
6
<p>
7
7
Yes, but only when you are initially creating it.
8
8
</p>
9
-
9
+
10
10
<h3>
11
11
What properties are required on the objects passed in to the array?
12
12
</h3>
13
-
13
+
14
+
<p>
15
+
The <code>id</code> and <code>text</code> properties are required on each object, and these are the properties that Select2 uses for the internal data objects. Any additional paramters passed in with data objects will be included on the data objects that Select2 exposes.
16
+
</p>
17
+
14
18
<h3>
15
19
How should nested results be formatted?
16
20
</h3>
17
-
21
+
18
22
<h3>
19
23
How many levels of nesting are allowed?
20
24
</h3>
21
-
25
+
26
+
<p>
27
+
Because Select2 falls back to an <code><optgroup></code> when creating nested options, only a single level of nesting can be supported.
28
+
</p>
29
+
22
30
<h3>
23
31
Why are <code><option></code> tags being created?
24
32
</h3>
25
-
33
+
26
34
<p>
27
35
The <code>data</code> option is a shortcut that Select2 provides which allows you to load options into your <code>select</code> from a data array.
28
36
</p>
29
-
37
+
30
38
<h3>
31
39
My objects don't use <code>id</code> for their unique identifiers, what can I do?
32
40
</h3>
33
-
41
+
42
+
<p>
43
+
You can re-map your identifier before passing it to Select2.
44
+
</p>
45
+
34
46
<h3>
35
47
My objects use a property other than <code>text</code> for the text that needs to be displayed
Copy file name to clipboardExpand all lines: docs/_includes/options-new/selections/placeholder.html
+32-8Lines changed: 32 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -2,28 +2,52 @@
2
2
<h2id="placeholder">
3
3
How can I have Select2 display a placeholder?
4
4
</h2>
5
-
5
+
6
+
<p>
7
+
Select2 supports displaying a placeholder by default using the <code>placeholder</code> option. This can be either a data object matching the placeholder option, or a string to display as the placeholder if you are using a blank placeholder option.
8
+
</p>
9
+
6
10
<h3>
7
11
My first option is being displayed instead of my placeholder
8
12
</h3>
9
-
13
+
14
+
<p>
15
+
This usually means that you do not have a blank <code><option></option></code> as the first option in your <code><select></code>.
16
+
</p>
17
+
18
+
<p>
19
+
Note that this does not apply to multiple selects, as the browser does not select the first option by default when multiple selections can be made.
20
+
</p>
21
+
10
22
<h3>
11
23
I am using AJAX, can I still show a placeholder?
12
24
</h3>
13
-
25
+
26
+
<p>
27
+
Yes, Select2 supports placeholders for all configurations. You will still need to add in the placeholder option if you are using a single select.
28
+
</p>
29
+
14
30
<h3>
15
-
Can I use a placeholder without a blank value?
31
+
Can I use an option without a blank value as my placeholder?
16
32
</h3>
17
-
33
+
34
+
<p>
35
+
The <code>placeholder</code> option allows you to pass in a data object instead of just a string if you need more flexibility. The <code>id</code> of the data object should match the <code>value</code> of the placeholder option.
36
+
</p>
37
+
18
38
<h3>
19
39
Can I change how the placeholder looks?
20
40
</h3>
21
-
41
+
42
+
<p>
43
+
The placeholder option should go through the standard templating methods, including <code>templateSelection</code>, so you can change how it is displayed.
44
+
</p>
45
+
22
46
<h3>
23
47
My placeholders aren't being displayed in Internet Explorer
24
48
</h3>
25
-
49
+
26
50
<p>
27
-
You need to include Placeholders.js on your page, or use the full build.
51
+
Select2 uses the native <code>placeholder</code> attribute on input boxes for the multiple select, and that attribute is not supported in older versions of Internet Explorer. You need to include Placeholders.js on your page, or use the full build, in order to add <code>placeholder</code> attribute support to input boxes.
0 commit comments