How to clear multiselect selections


Topic: How to clear multiselect selections

maheshbasapur pro premium asked 1 months 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>


Hello, documentation contains this section https://mdbootstrap.com/docs/standard/forms/select/#subsection-multi-selection

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);
multiSelectInstance.setValue([]);

https://mdbootstrap.com/snippets/standard/m-duszak/3303169#js-tab-view


Please insert min. 20 characters.
Status

Answered

Specification of the issue
  • User: Pro
  • Premium support: Yes
  • Technology: MDB Standard
  • MDB Version: MDB5 3.7.1
  • Device: Mackbook
  • Browser: safari
  • OS: Mac
  • Provided sample code: No
  • Provided link: No