From 916bb14414f2acc1dbb64b56fe7c9ada601fdc40 Mon Sep 17 00:00:00 2001 From: jdecuyper Date: Tue, 21 Jan 2014 17:53:33 -0600 Subject: [PATCH] Add documentation for hideSelectionFromResult --- select2-latest.html | 93 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 77 insertions(+), 16 deletions(-) diff --git a/select2-latest.html b/select2-latest.html index e3dacad5..e2309c9e 100644 --- a/select2-latest.html +++ b/select2-latest.html @@ -233,6 +233,7 @@ $("#e10_4").select2({
  • Sorting Displayed Results
  • Responsive Design
  • Diacritics Support
  • +
  • Allow duplicated tags
  • Documentation
  • @@ -979,21 +980,22 @@ $("#e18,#e18_2").select2();

    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

    +
    
    +              
    +
    +
    - + @@ -1603,6 +1632,38 @@ $("#select").select2({

    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).

    + hideSelectionFromResultfunction +

    Function that determines if the selected item should be displayed or hidden from the result list.

    + + + + + +
    ParameterTypeDescription
    dataobjectSelected 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.

    +