Does anyone know how to implement select all options in multiple select? it will be better if there is such option
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