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!


Topic: Adding a class to a select option

dncotterill free asked 6 years ago


Is it possible to get material select to copy the classes that have been applied to the <option> elements of the original select?


Sebastian Kaczmarek staff answered 6 years ago


It looks like we have overlooked this. We'll fix that for sure.

If you don't want to wait for the fix, you can work around this by modifying `buildSingleOption(...)` method in the `material-select.js` file. Please find the similar line:

this.$materialOptionsList.append($(`<li class="${disabled} ${optgroupClass}">${iconHtml}<span class="filtrable">${checkboxHtml} ${fa} ${$nativeSelectChild.html()}</span></li>`));

And change it to something like this one:

this.$materialOptionsList.append($(`<li class="${disabled} ${optgroupClass} ${$nativeSelectChild.attr('class')}">${iconHtml}<span class="filtrable">${checkboxHtml} ${fa} ${$nativeSelectChild.html()}</span></li>`));

(simply add `$nativeSelectChild.attr('class')` to the `<li>` class list). Then you will have to recompile and re-minify the package to have it in your mdb.min.js file. You can also do exactly the same thing directly in your mdb.js and then re-minify the file to have it in the mdb.min.js file. 



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

  • ForumUser: Free
  • Premium support: No
  • Technology: General Bootstrap questions
  • MDB Version: -
  • Device: PC
  • Browser: Chrome
  • OS: Win8
  • Provided sample code: No
  • Provided link: No