Select2 start with input field instead of dropdown

前端 未结 11 889
太阳男子
太阳男子 2020-12-08 06:44

I use the js library select2. This is a screenshot of what I have now:
Start:
\"enter

11条回答
  •  北海茫月
    2020-12-08 07:36

    $.fn.select2.amd.require([
      'select2/selection/multiple',
      'select2/selection/search',
      'select2/dropdown',
      'select2/dropdown/attachBody',
      'select2/dropdown/closeOnSelect',
      'select2/compat/containerCss',
      'select2/utils'
    ], function (MultipleSelection, Search, Dropdown, AttachBody, CloseOnSelect, ContainerCss, Utils) {
      var SelectionAdapter = Utils.Decorate(
        MultipleSelection,
        Search
      );
      
      var DropdownAdapter = Utils.Decorate(
        Utils.Decorate(
          Dropdown,
          CloseOnSelect
        ),
        AttachBody
      );
      
      $('.inline-search').select2({
        dropdownAdapter: DropdownAdapter,
        selectionAdapter: SelectionAdapter
      });
      
      $('.dropdown-search').select2({
        selectionAdapter: MultipleSelection
      });
      
      $('.autocomplete').select2({
        dropdownAdapter: DropdownAdapter,
        selectionAdapter: Utils.Decorate(SelectionAdapter, ContainerCss),
        containerCssClass: 'select2-autocomplete'
      });
    });
    .select2-selection__choice__remove {
      display: none !important;
    }
    
    .select2-container--focus .select2-autocomplete .select2-selection__choice {
      display: none;
    }
    
    
    
    
    
    

    With an inline search box

    With the search box in the dropdown

    With the selection hidden when it is focused

提交回复
热议问题