Login with:


Or:


Not a member? Sign Up

Forgot Password?

Signup with:


Or:


Already have an account? Log in

Re-initialising material select does not re-connect label

MDB SupportRe-initialising material select does not re-connect label
tblfounder Pro User asked 5 months ago

Hi,

I have a material_select object with an associated label and no options initially.
I dynamically set its options then re=initialize it using
$(‘.mdb-select’).material_select(‘destroy’);
$(‘.mdb-select’).material_select();

This results in the select being displayed with the first of the options selected, yet the label is permanently displayed within the select area – underneath the selected option text.
Selecting another option does not result in it moving above the select control as expected.

Is there something that can reconnect the operation of the label to the re-initialised select?

Regards

1 Answers
Adrian Sawicki answered 5 months ago

Hello,

If I properly understood your explanation, the only problem is the order of your declarations.
material select init -> material select destroy -> append your options -> material select init again.
About the first option it will always be selected because it’s like a placeholder/instruction for a user.

How I’ve checked it:

HTML:


<div class="col-md-6">
    <select class="mdb-select"></select>
    <label>Example label</label>
</div>

JS:


$(document).ready(function() {

    $('.mdb-select').material_select();
    $('.mdb-select').material_select('destroy');

    $('.mdb-select').append($("<option> test1 </option>"));
    $('.mdb-select').append($("<option> test2 </option>"));

    $('.mdb-select').material_select();

});

If it doesn’t help or in some way I misunderstood you, give me a bit more information of what you would like to do and I’ll try my best to help you.

mejia_09 Pro User replied 6 days ago

Hello, i have the same problem, after re-initialize material select the label is in front of select, i did what you say but still not working
here is an image with the problem
http://res.cloudinary.com/dnofvcpys/image/upload/v1507845719/material-select_oct25d.png

-the material select is in a modal