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:
- -
- -diff --git a/index.html b/index.html index 76bf675e..9f4f34f7 100644 --- a/index.html +++ b/index.html @@ -223,7 +223,6 @@ $("#e10_4").select2({
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:
- -
- -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.
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:
- -
- -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.