+
data
can also itself be a function that returns a results object:
+ +
+
-
+
+
The option can be set to a negative value
to permanently hide the search field
Only applies to single-value select boxes
@@ -1082,7 +1115,7 @@ $(document).ready(function () {
- If set to false the dropdown is not closed after a selection is made, allowing for rapid selection of multiple items. By default this option is set to true
.
+ If set to false the dropdown is not closed after a selection is made, allowing for rapid selection of multiple items. By default this option is set to true
.
@@ -1321,6 +1354,7 @@ $("#select").select2({
query(options)
Parameter | Type | Description |
---|---|---|
options.element | jquery object | The element Select2 is attached to |
options.term | string | Search string entered by user |
options.page | int | 1-based page number tracked by Select2 for use with infinite scrolling of results |
options.context | object | An object that persists across the lifecycle of queries for the same search term (the query to retrieve the initial results, and subsequent queries to retrieve more result pages for the same search term). When this function is first called for a new search term this object will be null. The user may choose to set any object in the results.context field - this object will then be used as the context parameter for all calls to the query method that will load more search results for the initial search term. The object will be reset back to null when a new search term is queried. This feature is useful when a page number is not easily mapped against the server side paging mechanism. For example, some server side paging mechanism may return a "continuation token" that needs to be passed back to them in order to retrieve the next page of search results. |
url | string/function | String containing the ajax url or a function that returns such a string. |
dataType | string | Data type for the request. ajax , jsonp , other formats supported by jquery |
quietMillis | int | Number of milliseconds to wait for the user to stop typing before issuing the ajax request |
cache | boolean | If set to false , it will force requested pages not to be cached by the browser. Default is false |
jsonpCallback | string/function | The callback function name for a JSONP request. This value will be used instead of the random name automatically generated by jQuery. It is preferable to let jQuery generate a unique name as it'll make it easier to manage the requests and provide callbacks and error handling. You may want to specify the callback when you want to enable better browser caching of GET requests. |
data | function |
Function to generate query parameters for the ajax request.
data(term, page)@@ -1398,8 +1434,11 @@ $("#select").select2({ |
<returns> | object | Results object. See "options.callback" in the "query" function for format. |
{contentType: "application/json;charset=utf-8"}
In order for this function to work Select2 should be attached to a input type='hidden'
tag instead of a select
.
For documentation of the data format see the query function
true
attempts to automatically size the width of the dropdown based on content inside.
+ adaptContainerCssClass(clazz)+
Parameter | Type | Description |
---|---|---|
clazz | string | Css class being copied |
<returns> | string | Css class to be applied or null/undefined/'' to not apply it |
adaptDropdownCssClass(clazz)+
Parameter | Type | Description |
---|---|---|
clazz | string | Css class being copied |
<returns> | string | Css class to be applied or null/undefined/'' to not apply it |
null
thereby filtering out all classes.
+ String escapeMarkup(String markup)
Function used to post-process markup returned from formatter functions. By default this function escapes html entities to prevent javascript injection.
@@ -1477,6 +1539,8 @@ $("#select").select2({Gets or sets the selection. Analogous to val
method, but works with objects instead of ids.
data
method invoked on a single-select with an unset value will return null
, while a data
method invoked on an empty multi-select will return []
Closes the dropdown
Disables Select2. During this mode the user is not allowed to manipulate the selection.
+Enables or disables Select2 and its underlying form component based on the boolean parameter.
Enables Select2.
+Toggles readonly mode on Select2 and its underlying form component based on the boolean parameter.
Fired when selection is changed.
-This event is not fired when the selection is changed using Select2's val()
method.
The event object contains the following custom properties:
Fired when the dropdown is shown.
+Fired before the dropdown is shown.
The event listener can prevent the opening by calling preventDefault()
on the supplied event object.
Fired after the dropdown is shown.
+ +Fired when a choice is highlighted in the dropdown.
+ +The event object contains the following custom properties: +
Fired when a choice is being selected in the dropdown, but before any modification has been made to the selection.
+ This event is used to allow the user to reject selection by calling event.preventDefault()
The event object contains the following custom properties: +
Fired when a choice is removed or cleared
+ +The event object contains the following custom properties: +
Fired when query function is done loading the data and the results list has been updated
+ +The event object contains the following custom properties: +
Fired when the control is focussed +
+Fired when the control is blurred +
+$.fn.select2.defaults
object. Properties changed in this object (same properties configurable through the constructor) will take effect for every instance created after the change
In order for this function to work Select2 should be attached to a input type='hidden'
tag instead of a select
.
For documentation of the data format see the query function