How to clear a selected value in Selectize.js dropdown?

后端 未结 6 1690
离开以前
离开以前 2021-02-05 00:39

I have a selectize.js dropdown and I have to clear the selected value .

I have tried this (as suggested in another question):

var selectize = $(\"#option         


        
6条回答
  •  孤城傲影
    2021-02-05 00:49

    $(document).on('click', 'div.selectize-input div.item', function(e) {
        var select = $('#services').selectize();
        var selectSizeControl = select[0].selectize;
        // 1. Get the value
        var selectedValue = $(this).attr("data-value");
        // 2. Remove the option
        select[0].selectize.removeItem(selectedValue);
        // 3. Refresh the select
        select[0].selectize.refreshItems();
        select[0].selectize.refreshOptions();
    });
    

    This do not remove the item from the select, just remove it from the selected options.

提交回复
热议问题