Topic: How to clear multiselect selections

maheshbasapur free asked 2 years ago

Expected behavior I am using multiselect in a form that is used to add some data to another form/table

Since I am handling the form submission in the javascript, I need to clear the previously selected items.

Selected options should get unselected

Actual behavior There is no documentation of how to do

Resources (screenshots, code snippets etc.)

<select class="select" multiple name="role" id="roles-multi-select">
<option value="1">A</option>
<option value="2">B</option>
<option value="3">C</option>

Michał Duszak staff answered 2 years ago

Hello, documentation contains this section

which will suite your needs. Here's a snippet on how to do it properly. Just pass an empty array in the setValue method.

const multiSelect = document.querySelector('#multiSelection');
const multiSelectInstance = mdb.Select.getInstance(multiSelect);

Please insert min. 20 characters.


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



Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB Standard
  • MDB Version: MDB5 3.7.1
  • Device: Mackbook
  • Browser: safari
  • OS: Mac
  • Provided sample code: No
  • Provided link: No