Select2 start with input field instead of dropdown

前端 未结 11 917
太阳男子
太阳男子 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:28

    Use these properties

    $('#placeSelect').select2({
    width: '100%',
    allowClear: true,
    multiple: true,
    maximumSelectionSize: 1,   
    });
    

    just call this function on onchange event of dropdown

    function ResentForMe(){
    var _text=$('.select2-selection__rendered li:first-child').attr('title');
    $('.select2-selection__rendered li:first-child').remove();
    $('.select2-search__field').val(_text);
    $('.select2-search__field').css('width','100%');
    }
    

    Note: Remove "Multiple" attribute from select

提交回复
热议问题