Bootstrap select multiple (мультиселект с предварительным поиском)

js

$('#years').selectpicker('refresh');

function change_in_year()
{
var yearSelect = new Array();
var i = 0;


$("#years option:selected").each(function(){
        yearSelect[i] = $(this).val();
        i++;
});

var yearS = new Array();
var i = 0;

$("#years option").each(function(){
        yearS[i] = $(this).val();
        i++;
});

if(yearSelect[0] == 0)
{


        yearS.forEach(function(entry) {
            if(entry != "0")
            {
            $('#'+entry).prop('disabled',true);
            $('#'+entry).prop('selected',false);
            }
        });
        $('#years').selectpicker('refresh');
}
if( (yearSelect[0] != 0) )
{

        yearS.forEach(function(entry) {
            $('#'+entry).prop('disabled',false);
        });
        $('#years').selectpicker('refresh');
}   
}

html

<select id="years" class="select" data-live-search="true" onchange="change_in_year()" multiple="">
<option id="2011" value="2011">2011</option>
<option id="2012" value="2012">2012</option>
<option id="2013" value="2013">2013</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2017">2017</option>
<option value="2018">2018</option>
</select>

найдено тут + там же пример работы внизу