Disabled options
@@ -1041,6 +1043,7 @@ $(document).ready(function () { }); $('#e21').select2('data', preload_data ) }); +Lock selections
@@ -1084,10 +1087,36 @@ $(document).ready(function () {Allow duplicated tags
+In multiple mode, select2 doesn't allow the same tag to be selected more than once. This default behavior can be overridden by implementing the hideSelectionFromResult
function:
+ +
+ +Example Code
+ +Function can be used when the dropdown is configured in single and multi-select mode. It is triggered after selecting an item. In single mode it is also triggered after initSelection (when provided).
+Function that determines if the selected item should be displayed or hidden from the result list.
+Parameter | Type | Description |
---|---|---|
data | object | Selected data. |
By default, the selected item is visible in the result list in single mode and hidden in multi-select mode.
+ This behavior can be overridden by implementing the hideSelectionFromResult
function.
For instance, in the case of a single select box it can be used to hide the selected item from the result list:
++function hideSelectedItem(selectedObject){ + return true; +} + +$("#e1").select2({ + hideSelectionFromResult: hideSelectedItem +}) ++
More complex behavior can be achieved by reading the text of the selected item:
++function hideAlaskaFromResult(selectedObject){ + return selectedObject.data("select2-data").text == "Alaska" ? true : false; +} + +$("#e1").select2({ + hideSelectionFromResult: hideAlaskaFromResult +}) ++
The return value of hideSelectionFromResult
is a boolean. It returns undefined if it is not implemented.