2

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.

isherwood
  • 58,414
  • 16
  • 114
  • 157
d0t_m
  • 87
  • 7
  • Sorry, I don't understand what are you struggling with. When you retrieve data from DB, you can use ```slim.setData(dataFromDB)```, right? – ikhvjs Jul 02 '21 at 14:30
  • What does "N° select" mean here? – isherwood Jul 02 '21 at 14:36
  • If you mean you're creating _some number_ of selects, please revise your snippet to reflect that (and use plain language to describe it). – isherwood Jul 02 '21 at 14:43

0 Answers0