mdb-select (Set the selected = true) no working


Topic: mdb-select (Set the selected = true) no working

Troy Smith asked 5 years ago

Expected behavior I should be able to default the items in the mdb-select to already selected or not selected.
Actual behavior I cannot set the values. I have tried using selected= true. But this does not work. I have confirmed that my FIRST object in my array is set to selected = true; But that has no impact on my mdb-select list. Resources (screenshots, code snippets etc.) Here is the code I am setting JS************************************************** onReply(){ this.groupOptionsSelect = [] let x = JSON.parse(localStorage.getItem('availableUsers')) for(let a of x){ let obj = { value:a.userid, label:a.fullname, email: a.email, group:false, selected: false, } this.groupOptionsSelect = [...this.groupOptionsSelect, obj]

}  
        this.groupOptionsSelect[0].selected = true
        this.selectedValue = '148'
        console.log('emails', this.groupOptionsSelect)

} getValues(emails){ console.log('Values', emails) } Here are the first two entries in my groupOptionSelect: value: 148 label: "Bernard, Jim" email: "jbup@hospice.us.com" group: false selected: true

value: 738 label: "Betty, RN" email: "rn1@hospice.us.com" group: false selected: false

HTML **************************


Arkadiusz Idzikowski staff commented 5 years ago

Please provide html as well and fix formatting in your post because the code is unreadable.

You can find an example on how to set preselected default value in our documentations (there is an example for reactive forms as well):

https://mdbootstrap.com/docs/angular/forms/select/#preselect-template


Please insert min. 20 characters.

FREE CONSULTATION

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

Status

Open

Specification of the issue
  • User: Free
  • Premium support: No
  • Technology: MDB Angular
  • MDB Version: 9.0.1
  • Device: desktop
  • Browser: chrome
  • OS: ubuntu
  • Provided sample code: No
  • Provided link: No