Topic: Multi Select Setting Values
I am trying to dynamcially set the values of a multi select dropdown. using the example where we set the values directly is seems to work but if i put them into a variable first then they dont.
Dawid Wajszczuk staff answered 3 years ago
Hi,
It works fine for me. Here is the snippet https://mdbootstrap.com/snippets/standard/d-wajszczuk/3712145#js-tab-view. The variable just needs to be an object. There were unnecessary quotation marks.
Keep coding,
Dawid
jamie pro premium priority answered 3 years ago
thanks, i was trying to create a string from my data rather than creating an array
const values = [];
options = Array.from(document.querySelectorAll('#categories option'));
for (var i = 0; i < cat.length; i++) {
values.push(cat[i].categoryid);
}
const multiSelect = document.querySelector('#categories');
const multiSelectInstance = mdb.Select.getInstance(multiSelect);
multiSelectInstance.setValue(values);
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- User: Pro
- Premium support: Yes
- Technology: MDB Standard
- MDB Version: MDB5 3.10.2
- Device: pc
- Browser: chrome
- OS: 11
- Provided sample code: No
- Provided link: No