Materialize: Select All option for multiple select

Created on 14 Jun 2016  ·  8Comments  ·  Source: Dogfalo/materialize

Does anyone know how to implement select all options in multiple select? it will be better if there is such option

Select js question

All 8 comments

I'm seeking how to select 1 options with JS.

I try to do so, but I can't.

I found !
You have to manually add property "select" on all your options you want and to refresh the display with the jquery script.

 var select = form.find('#countries'); //find select
            for (var index in user.countries) {
                select.find("option[value='" + user.countries[index] + "']").prop('selected', true); //select all countries
            }

            select.material_select(); //refresh display

@axellebot Could you show me your html code??

Be advise, I'm using twig ;)

<div class="input-field col s6">
                        <i class="material-icons prefix">terrain</i>
                        <select id="countries" name="form_user[countries][]" multiple>
                            <option value="" disabled selected>Choose Countries</option>
                            {% for country in countries %}
                                <option value="{{ country.id }}">{{ country.name }}</option>
                            {% endfor %}
                        </select>
                        <label>Countries</label>
                    </div>

Thanks! I will use that as reference.:D

I have an easy way with jquery!!!

$("#your_multiple_select_id").val("");
$("#your_multiple_select_id").material_select(); //refresh display

the HTML...

<div class="input-field col s12">
    <select id="your_multiple_select_id" multiple>
      <option value="" disabled selected>Choose your option</option>
      <option value="1">Option 1</option>
      <option value="2">Option 2</option>
      <option value="3">Option 3</option>
    </select>
    <label>Materialize Multiple Select</label>
  </div>

I did it with

$("#select_id option").prop("selected", true)
$("#select_id").material_select()

Which is the simple select-all version of what @axellebot is doing

Was this page helpful?
0 / 5 - 0 ratings

Related issues

acierpinski picture acierpinski  ·  3Comments

artur99 picture artur99  ·  3Comments

onigetoc picture onigetoc  ·  3Comments

samybob1 picture samybob1  ·  3Comments

SoproniOli713 picture SoproniOli713  ·  3Comments