4
I need that only in the select option that is selected the "Leader" option, it does not assign the "disabled", only in the other selects daughters.
The logic is that only a user can be a leader, but when I select a leader, this option is "disabled", and when sending the data he cannot send the value precisely because the option is disabled.
Here is a simulation of the problem:
$('select').change(function() {
var sel = $(this);
disableThis(sel);
$('.selectpicker').selectpicker('refresh');
});
function disableThis(sel) {
var temSelecionado = false;
$("option[value='1']").each(function() {
if (this.selected) {
temSelecionado = true;
$(this).parent().each(function() {
$(this.options).each(function() {
if ($(this).val() != "1") {
$(this).prop("disabled", true);
}
})
});
}
});
$(sel).children().each(function() {
var thisLider = false;
// verifica se o lider estar selecionado
if ($(this).val() == "1" && $(this).prop("selected")) {
thisLider = true;
}
// caso nao estiver, desabilita
if ($(this).val() != "1" && thisLider) {
$(this).prop("disabled", true);
}
});
//faz uma verificacao nos demais selects e se o lider estiver selecionado, desabilitara
$("select").children().each(function() {
if ($(this).val() == "1" && temSelecionado) {
$(this).prop("disabled", true);
}
});
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/js/bootstrap.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.6.3/js/bootstrap-select.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/css/bootstrap.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.6.3/css/bootstrap-select.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>
I understood @Franco, but the problem is that in select where the option "Leader" is selected, the other options of this same select need to be disabled, because the user who is selected as "Leader" should not have more functions, he should only be leader... understand?
– André Albson
@Andréalbson I made an edition. I believe it is now closer than you want.
– Franco Pan