1
I have a problem when I uncheck an option on a particular select. I cannot make the select option, when unchecked, return to its initial state, that is, how to reset. So, I thought Jquery detect when an option is unchecked, but I don’t know how to do it.
Below is a simulation of my problem:
var unique = 1;
$('select').on('change', function(){
var options = $('.selectpicker').find('option').filter(function(){
return unique == this.value;
});
//para nao ocultar do select pai
if(unique == this.value){
options.hide();
$(this).find('option[value="'+unique+'"]').show();
$(this).each(function() {
$(this.options).each(function() {
if(($(this).val() == "1")){
}
if ($(this).val() != "1") {
$(this).prop("disabled", true);
}
})
});
$('.selectpicker').selectpicker('refresh');
}
else {
if($(this).find('option[value="'+unique+'"]:visible').size() > 0){
options.show();
}
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.6.3/js/bootstrap-select.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/js/bootstrap.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.6.3/css/bootstrap-select.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/css/bootstrap.css" rel="stylesheet"/>
<select class="selectpicker" id="funcao" multiple>
<option value="1">Líder</option>
<option value="conhecimento">Para Conhecimentor</option>
<option value="participante">Participante</option>
</select>
<br><br>
<select class="selectpicker" multiple>
<option value="1">Líder</option>
<option value="conhecimento">Para Conhecimentor</option>
<option value="participante">Participante</option>
</select>
<br><br>
<select class="selectpicker" multiple>
<option value="1">Líder</option>
<option value="conhecimento">Para Conhecimentor</option>
<option value="participante">Participante</option>
</select>
<br><br>
<select class="selectpicker" multiple>
<option value="1">Líder</option>
<option value="conhecimento">Para Conhecimentor</option>
<option value="participante">Participante</option>
</select>
Perfect, @Sorry! Thanks for the help!
– André Albson