Topic: Dynamic select initialization

nick.kaynes priority asked 3 months ago


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

https://mdbootstrap.com/docs/standard/forms/input-fields/#section-dynamic-input-initialization

I tried

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

but get an error.


kpienkowska staff answered 3 months 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 3 months 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 3 months 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?


kpienkowska staff answered 3 months ago



Please insert min. 20 characters.

FREE CONSULTATION

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

Status

Answered

Specification of the issue

  • User: 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