Select2 start with input field instead of dropdown

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

    In my case, I wanted the user's selections from the dropdown to appear in a list below the dropdown, rather than working like a regular dropdown list. So this workaround worked for me:

    $('#myselect').select2({
        multiple:true
    })
    .on('select2:select', function (e) {
        //clear the input box after a selection is made
        $(this).val([]).trigger('change');
    });
    

    Of course that won't work if you want the selected item to stay selected in select2's input box like it does with a regular select2 multiselect list.

提交回复
热议问题