I attempted to utilize the "setSelected" option on my multiselect feature, but I noticed that it does not function with div elements (at least I could not make it work myself). I am endeavoring to create two synchronized multiselects using this example: but focusing only on the last two inputs.
var options = [
{ text: 'item1', value: 'item1'},
{ text: 'item2', value: 'item2'},
];
var teste1 = null;
var teste2 = null;
let isTeste2 = true;
var $testes = $('#teste1-id')
if (isTeste2)
$testes = $testes.add('#teste2-id')
var install = function () {
$testes.bsMultiSelect({
options: options
});
if (isTeste2) {
$('#teste1-id').on('dashboardcode.multiselect:change', function () {
$('#teste2-id').bsMultiSelect("UpdateOptionsSelected");
})
}
}
install();
$("#btn").click(
function(){
options[0].selected = true;
var api1 = $testes.BsMultiSelect();
api1.updateOptionSelected(0);
}
)
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8fffe0ffffeafda1e5fccfbea1beb9a1bf">[email protected]</a>/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/@dashboardcode/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bfddccd2cad3cbd6ccdad3dadccbff8f9189918d87">[email protected]</a>/dist/js/BsMultiSelect.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<label class="control-label" for="teste1-id">Teste1</label>
<div id="teste1-id"></div>
<label class="control-label" for="teste2-id">Teste2:</label>
<div id="teste2-id"></div>
<br/>
<button id="btn">Click Me</button>
Can you assist me in finding a solution, please?