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: MDB multiple select default value

O1ivier priority asked 5 years ago


Hi,

I encounter an issue while trying to determine default value for my multiple mdb-select and while the values are numbers.The multiple mdb-select works fine when it's string values.

This is my select :

<select id="product" name="product[]" class="mdb-select md-form initialized" multiple="" searchable="Search">
    <option value="">None</option>
    <optgroup label="Products Cat 1">
        <option value="22">Product 1</option>
        <option value="23">Product 2</option>
        <option value="24">Product 3</option>
        <option value="25">Product 4</option>
    </optgroup>
    <optgroup label="Products Cat 2">
        <option value="1">Product 5</option>
        <option value="2">Product 6</option>
        <option value="3" selected>Product 7</option>
        <option value="4">Product 8</option>
    </optgroup>
</select>

Of course, I initialized the select :

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

My problem is : the mdb select displayed don't have the product with value "3" checked (Product 7 in my case), it has the product with value "22" checked instead (Product 1)...

I tried to destroy et initialize again the select but it did nothing.I also tried to display the value of my select in console and I have this result :["", "22", "3"] instead of ["3"].

I don't want the "22" value, I never checked it ! The value "3" isn't checked in my select neither...

Thank you.

EDIT : Snippet if needed : https://mdbootstrap.com/snippets/jquery/o1ivier/433268


Piotr Glejzer staff commented 5 years ago

Yea, I see the problem. Sorry about that bug. I added a task for that to check/repair it as soon as possible.


O1ivier priority commented 5 years ago

Hello,

Do you know approximately when will this problem be solved ?

Thanks


Piotr Glejzer staff commented 5 years ago

I'm already looking into this. I will try to fix this a soon as possible but It will be probably fixed in the next release.


gianlucagiacometti priority answered 5 years ago


@jzraibi you need to do something like:

$("#mymultipleselect").val(['val1','val2','val3']).trigger('change');

jiri.lorenz@panflex.cz priority answered 5 years ago


Please is this problem solved. Now I have the same issue.

Many thanks for answer.


Piotr Glejzer staff commented 5 years ago

which version do you use?


jiri.lorenz@panflex.cz priority commented 5 years ago

Sorry. MDB Pro 4.8.2


Piotr Glejzer staff commented 5 years ago

Ok, we will check it. Thanks for the report.


jzraibi priority commented 5 years ago

i am not able to SET multiple values for multiple select (mdb-select)


Sebastian Kaczmarek staff commented 5 years ago

@jzraibi what exactly does not work? Take a look at my snippet, it seems to work well: https://mdbootstrap.com/snippets/jquery/s-kaczmarek/1427106



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: Priority
  • Premium support: Yes
  • Technology: MDB jQuery
  • MDB Version: 4.5.12
  • Device: Desktop
  • Browser: Google Chrome
  • OS: Windows 10
  • Provided sample code: No
  • Provided link: Yes