Topic: How to clear multiselect selections

maheshbasapur free asked 3 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 3 years ago


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.

FREE CONSULTATION

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

Status

Answered

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