I am using a plugin called Slim Select SlimSelect.
At the moment I am creating N° select with a foreach loop, and I need to set previous saved options within each select. The problem is, I cannot create variables recursively (or at least I don't know how to do it), and SlimSelect must be attached to a variable to use its .set()
method.
Here is the code from SlimSelect website
const slim = new SlimSelect({
select: '#selectMultiMandatory'
});
const data = [
{ value: 'A', text: 'A', mandatory: true },
{ value: 'B', text: 'B' },
{ value: 'C', text: 'C' }
]
slim.setData(data)
slim.set(["A", "C"])
<script src="https://cdnjs.cloudflare.com/ajax/libs/slim-select/1.27.0/slimselect.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/slim-select/1.27.0/slimselect.min.css" rel="stylesheet"></link>
<select id="selectMultiMandatory" multiple>
I need to set the data with the one I retrieve from the DB and then set the options based on previous records.
I already tried triggering clicks on the elements but it doesn't work at all.
I am using Vanilla JS.