Holiday Notice: Support will be provided on a limited scale from December 24th, 2024, to January 2nd, 2025. Happy holidays and a wonderful New Year!

maroja4 pro asked 4 years ago


How can I automatically select a value that comes from a query in the database?

I tried this but it doesn't work, on MDB4 there are no problems with the same example.


Arkadiusz Idzikowski staff answered 4 years ago


Currently, it's not possible to set the component value like in the MDB4 select. We will add a better solution for this use case in the upcoming updates.

For now, you need to select the corresponding option and re-initialize the select component manually:

HTML:

<select id="my-select" class="select">
  <option value="1">One</option>
  <option value="2">Two</option>
  <option value="3">Three</option>
</select>

JS:

  const value = '3';
  const select = document.querySelector('#my-select');
  const correspondingOption = Array.from(select.options).find((option) => option.value === value);
  correspondingOption.selected = true;

  const instance = mdb.Select.getInstance(select);
  instance.dispose();
  new mdb.Select(select);

Andrew Ford priority commented 4 years ago

In the MDB5 documents for SELECT, it redirects to the jQuery 4.19.1 SELECT docs. https://mdbootstrap.com/docs/standard/forms/select/


Arkadiusz Idzikowski staff commented 4 years ago

It should work correctly now. Please let us know if you notice any further problems with the documentation.


Andrew Ford priority commented 4 years ago

@Arkadiusz Idzikowski I am still getting redirected to the jQuery docs.


Arkadiusz Idzikowski staff commented 4 years ago

@Andrew Ford Could you check if this problem still exist when you use incognito mode or other browser?


Andrew Ford priority commented 4 years ago

I'm primarily using Edge, I also tried in Incognito - redirects Still redirects on Chrome. Firefox - redirects Opera (also in Incognito) - redirects Safari on my phone - redirects

I clean my cache daily, and I just installed Chrome and Firefox while typing this.


Michal Szymanski staff commented 4 years ago

We are trying to figure out what's going on. Can you check it now?


Andrew Ford priority commented 4 years ago

@Michal Szymanski It worked.


Michal Szymanski staff commented 4 years ago

Alright, thank you for the information and sorry for the inconvenience.



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

  • ForumUser: Pro
  • Premium support: No
  • Technology: MDB Standard
  • MDB Version: 1.0.0
  • Device: LAPTOP
  • Browser: CHROME
  • OS: W10
  • Provided sample code: No
  • Provided link: No