Topic: Material Select enable/disable via javascript

swipiidev free asked 7 years ago


Hi, We are using a material select component and trying to enable/disable it via javascript. We can destroy the material select no problem using $('.mdb-select').material_select('destroy'); but when we reinitialise with $('.mdb-select').material_select() we reinitialise the disabled version, I can't see anything in your documentation around reinitialising with a different status. If we call $('.mdb-select').material_select() twice we end up with two material selects one disabled and one enabled. Can you please advise how to enable and disable material selects via javascript? Thanks and kind regards, Caroline

rogertor pro answered 5 years ago


jgjgjgjhhjbjjh hjh jh jhj


Bartłomiej Malanowski staff commented 5 years ago

I think it's not that kind of content we're looking for. If you're having troubles with our library, please ask the real question. If you just want to follow this thread, you can use the "subscribe" button on the right sidebar of this page


Josip Tomašev priority answered 7 years ago


Adrian Maybe better solution is:

$(".mdb-select").material_select();
$("#FilterType").material_select("destroy")
$("#FilterType").removeAttr("disabled")
$("#FilterType").material_select();
On page with more select field you can see flicker, but if only one field was affected less time need for rerender and you have less side effect on rest of page

swipiidev free answered 7 years ago


Thanks, I'll give this a try.

Adrian Sawicki free answered 7 years ago


Hello, If you want to remove disabled. It's enough to remove this attribute.
$(".mdb-select").material_select();
$(".mdb-select").material_select("destroy")
$("#FilterType").removeAttr("disabled")
$(".mdb-select").material_select();
Regards, Adrian

swipiidev free answered 7 years ago


Hi Madgalena, We are just trying to dynamically disable and re-enable a material select (dropdown). Here is our html to create a disabled select list:

 <div class="col-3">
            <select name="SelectedFilter.FilterType" id="FilterType" class="mdb-select" disabled>             
                <option value="0">Customer has visited</option>
                <option value="1">Customer has not visited</option>
        </select>
</div>
Here is our javascript to initialise the select element: $('.mdb-select').material_select(); We have tried using $('.mdb-select').material_select('destroy'); to remove the select then using $('.mdb-select').material_select(); to re initialise it, however the select element is still disabled (we want to enable it using javascript) Can you please advise? Thanks

Magdalena Obalska free answered 7 years ago


Hi, Caroline, paste your code here, please, and tell me more precisely what do you expect to get.

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