Topic: mdb.Select.setValue() not working correctly
const select = document.querySelector('.select');
const singleSelectInstance = mdb.Select.getInstance(select);
if (singleSelectInstance) singleSelectInstance.setValue(value);
This code checks to see if there's an mdb.Select instantiated, gets that instance, and sets the value, resulting in the rendered mdb.Select to change which option is displayed as well as the underlying select so I can get the selectedIndex or value later in my code.
Snippet harness doesn't seem to like function variables? Not sure. Feel free to alter it.
Doesn't change the mdb.Select appearance or element value on my local environment either.
Resources (screenshots, code snippets etc.) https://mdbootstrap.com/snippets/standard/dhermann/4099918
For some reason it's not working via HTML onclick event attribute. This example works fine if you add listener in JS.
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
- User: Premium
- Premium support: Yes
- Technology: MDB Standard
- MDB Version: MDB5 4.1.0
- Device: Desktop
- Browser: Safari
- OS: macOS Monterrey 12.0.1
- Provided sample code: No
- Provided link: Yes