mdb.Select.setValue() not working correctly


Topic: mdb.Select.setValue() not working correctly

dhermann pro premium asked 2 years ago

Expected behavior 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.

Actual behavior

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


mlazaru staff answered 2 years ago

For some reason it's not working via HTML onclick event attribute. This example works fine if you add listener in JS.

https://mdbootstrap.com/snippets/standard/mlazaru/4106250


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue
  • User: Pro
  • 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