Preselect multiple Values in mdb-select


Topic: Preselect multiple Values in mdb-select

bfk.portal pro asked 6 years ago

Hello, I need to preselect more than one value in a mdb-select, The Data i get is async and when I tried it like in your example it didn't work. I tried it like this:
pushOrganisationsIntoMultiSelect() {

this.allOrganisationsMultiSelect= [];

this.allOrganisations.forEach(organisation=> {

this.allOrganisationsMultiSelect.push({value:organisation.id, label:organisation.name, selected:true});

this.selectedValue=organisation.id;

});

}

But that didn't work out so I tried this work around but this didn't work for all use cases:

this

          .organisationSelect

          .optionList

          .options

          .forEach(option => {

            this

              .participants

              .forEach(participant => {

                if (option.wrappedOption.label === participant.name) {

                  option.selected = true;

                }

              });

          });
But it didn't work everywhere so i wanted to ask if there is a better way to do it. with best regards, Matthias Herzog

Arkadiusz Idzikowski staff answered 6 years ago

Dear Matthias, If you want to preselect more than one value at the same time you need to use multiple select and selected value must be an array of strings. You also need to update your options array with spread operator instead of push method. For example:
this.allOrganisationsMultiSelect = [...this.allOrganistaionsMultiSelect,{value:organisation.id, label:organisation.name, selected:true}];
Regards, Arek
Please insert min. 20 characters.

FREE CONSULTATION

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

Status

Resolved

Specification of the issue
  • User: Pro
  • Premium support: No
  • Technology: MDB Angular
  • MDB Version: 6.2.2
  • Device: Desktop
  • Browser: Chrome
  • OS: Windows
  • Provided sample code: No
  • Provided link: No
Tags