Secondary initialize mdb-select is possible


Topic: Secondary initialize "mdb-select" is possible

Boris Akimenko pro asked 6 years ago

Hi guys! Secondary initialized  $('.mdb-select').material_select(); gives multiple material view on already initialized selects. So if I dynamically add some <select> element, then I have to get this element and initialize it instead just run $('.mdb-select').material_select().

Mikołaj Smoleński staff answered 6 years ago

Hi Boris, Can You try to give select a new class each time You add the next select? Then You can initialize only this select without changing the others. Regards

Boris Akimenko pro commented 6 years ago

This is not good if I try to initialize a several new elements.


Mikołaj Smoleński staff commented 6 years ago

What about the below solution? Best regards


Alex Gotardi pro answered 6 years ago

Boris, See https://mdbootstrap.com/support/fix-multi-material-select/ or destroy and create mdb-select, but's more expensive to browser cpu-usage  
// Material Select Destroy
$('.mdb-select').material_select('destroy');

Mikołaj Smoleński staff commented 6 years ago

Thanks for sharing Your solution!

Boris Akimenko pro commented 6 years ago

Thank you Alex! But destroy is not good way as you say :) Init function must check selects by class which added when it initialized

Mikołaj Smoleński staff commented 6 years ago

Boris, is Alex solution working in Your project?

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: Pro
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No