문제

I am using BootStrap-Select for multi-selection purpose.If i have 10 options and I select 3 or more options and now going to select a 4th one then the other selected option unselect randomly. I am using bootstrap select following functions:

$('#deptID').selectpicker('refresh');
$('#'+entry).prop('disabled',false);

BootStrap-Select Reference

Select

<select id="years" class="select" data-live-search="true" class="selectpicker col-md-12" 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 id="2014" value="2014">2014</option>
<option id="2015" value="2015">2015</option>
<option id="2016" value="2016">2016</option>
<option id="2017" value="2017">2017</option>
<option id="2018" value="2018">2018</option>
</select>

change_in_year()

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');
}   
}

this is the actual working code same as mine and working properly in jsFiddle. But on my system selecting option cause deselection of other selected options

jsFiddle Link

도움이 되었습니까?

해결책

The Above Work Fine On JSFiddle. I Changed the jquery.js and bootstrap.js. Now its work Fine in my system also..

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top