Topic: Default selected value for MDBSelect

kask free asked 3 years ago


Hello,

I have a page which loads data from database and shows them on form components. I'm having issues to apply selected value for MDBSelect component. I pass following data to the component:

...
17: {text: 'Satakunta', value: 4}
18: {text: 'Uusimaa', value: 1, selected: true}
19: {text: 'Varsinais-Suomi', value: 2}
...

I have MDBSelect component set so:

<br> <MDBSelect<br> label={"Maakunta"}<br> data={options}<br> getSelectedValue={e => onChange(e)}<br> /><br>

I would expect the value 1 to be selected and word Uusimaa to be displayed, however nothing seems to be selected:enter image description here

I tried to set preselect property to false as per documentations basic example (the property seems to be missing from the API tab) but nothing seems to be changing.

How I can set the currently selected value?

By the way, I have MDB5 version 1.4.0 instead of selected 1.3.0 as that version is currently missing from the "Specify your issue" select.


Krzysztof Wilk staff commented 3 years ago

Hi!

Do you have some errors in your console? Is it possible to share your code with me (creating i.e. sample GitHub repository or using our snippets, I mean onChange method or data from API - remember that it has to be an array of objects)?


kask free commented 3 years ago

I created a sample project here: https://github.com/kaskii/mdb-issue

I removed my oauth2 token from package.json and package-lock.json file. You can see as when data changes, the selected property seems to be ignored. Is there a better way to change selected value programmatically other than initializing new data (with selected: true)? Using value={1} it will just print 1 into the select field instead of selecting option with value 1.


Krzysztof Wilk staff commented 3 years ago

Hi!

Now I see the problem. As you can see - the data is set dynamically almost correctly, but there's still a problem with a selected property of the item object. There's no way to set dynamically a value of the select. We'll fix it in the next release in about one or two weeks, sorry for that :(


kask free commented 3 years ago

No worries, I can use default HTML select meanwhile. Is there a changelog available that I can keep an eye on to see when a new version is released?


Krzysztof Wilk staff commented 3 years ago

Sure, you can see the changelog here: https://mdbootstrap.com/docs/b5/react/getting-started/changelog/ :)



Please insert min. 20 characters.

FREE CONSULTATION

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

Status

Opened

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB React
  • MDB Version: MDB5 1.3.0
  • Device: PC
  • Browser: Chrome
  • OS: Windows
  • Provided sample code: Yes
  • Provided link: No