How do I when I select the Leader option , javascript does not allow another function to be selected (multiselect)?
The scenario is as follows: Each select represents the roles of each user.
The user who is selected as Leader , can not have any other role; only Leader.
If the option is different from Leader , then javascript allows you to select more than one function.
Here's my attempt:
$("select").on("change", function() {
var self = $(this);
var values = self.val();
$("select").not(self).each(function() {
var _values = $(this).val();
if (_values == "1") {
$(this).selectpicker('deselectAll')
for (var v = _values.length; v--;) {
if (values.indexOf(_values[v]) >= 0) {
_values.splice(v, 1);
}
}
$(this).val(_values);
}
});
$(".selectpicker").selectpicker("refresh");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script><scriptsrc="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><linkhref="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" multiple>
<option value="1">Líder</option>
<option value="10">Para Conhecimentor</option>
<option value="11">Participante</option>
</select>
<br><br>
<select class="selectpicker" multiple>
<option value="1">Líder</option>
<option value="10">Para Conhecimentor</option>
<option value="11">Participante</option>
</select>
<br><br>
<select class="selectpicker" multiple>
<option value="1">Líder</option>
<option value="10">Para Conhecimentor</option>
<option value="11">Participante</option>
</select>
<br><br>
<select class="selectpicker" multiple>
<option value="1">Líder</option>
<option value="10">Para Conhecimentor</option>
<option value="11">Participante</option>
</select>