Topic: Dynamic select initialization

nick.kaynes priority asked 1 year ago

How do you do dynamic initialization for select component , like for input

I tried

    document.querySelectorAll('.select').forEach(function (selectNode) {
        new mdb.Select(selectNode).init();

but get an error.

Kamila Pieńkowska staff answered 1 year ago

You can do that. And your initial code was almost good. You don't need to call init method. It will look like this:

document.querySelectorAll('.select').forEach(function (selectNode) {
    new mdb.Select(selectNode);

nick.kaynes priority commented 1 year ago

No its not the same. This will recreate all select nodes even ones that are ready created resulting in 2 select components. The input initialization works with .init() because it only recreates component if not allready created.

nick.kaynes priority answered 1 year ago

This means I have to write all my selects as strings. Not an option. Isnt there a consistent way to do it like the input element where you have a method .init() on all instances with the class?

Kamila Pieńkowska staff answered 1 year ago

Please insert min. 20 characters.


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



Specification of the issue

  • ForumUser: Priority
  • Premium support: Yes
  • Technology: MDB Standard
  • MDB Version: MDB5 4.4.0
  • Device: windows desktop
  • Browser: chrome
  • OS: windows
  • Provided sample code: No
  • Provided link: Yes