Topic: Unselect mdb-select control using Javascript / Jquery

KenHartwigsen free asked 6 years ago


I want to clear the previously selection dropdown option that was selected from within a javascript function. How can I do this

MDBootstrap staff answered 4 years ago


Hi Eeesbk,

To restart our material select you can use attribute destroy: true, like this:

   $('.mdb-select').materialSelect({
        destroy: true
   });
   $('.mdb-select').materialSelect();

This way whole select will be initialized again and all changes that user caused will be reverted.

Best Regards, Piotr


Eeesbk free answered 4 years ago


Hello. Im clear select value $(".active").removeClass(); and submit form... select not clear!! help pls


Jakub Strebeyko staff answered 6 years ago


Hi there Ken, Thanks for reaching out onto our forum. There seem to be numerous ways to proceed, depending on what specifically you mean by 'unselect'. In general, .material_select() function hides the select html element from sight, and what you're clicking on (the options) are span elements, children to lis within a newly-created, js-initiated ul element. And so, what selecting is in that context is granting these parent li elements the .active and .selected classes. The easiest way to unselect in that sense (aka not getting them selected) would be to create a function removing the classes right when they're added, like so: var select = $('.mdb-select'); select.material_select(); select.on("change", function(){ $(".active").removeClass(); }); Please let us know whether I read you correctly. With Best Regards, Kuba

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: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No
Tags