Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic /How to select multiple options from select control(Maximum selection will 3 options only)?

I'm using the Ionic 1.3.16 version currently. Here I need to select multiple options in my select control.

Here my ionic HTML code:

<div class="list">
    <label class="item item-input item-select">
        <div class="input-label">
            Lightsaber
        </div>
        <select>
            <option>Blue</option>
            <option selected>Green</option>
            <option>Red</option>
        </select>
    </label>
</div>
like image 518
Arul Avatar asked Jun 01 '15 05:06

Arul


People also ask

How can I select multiple dropdown options?

Selecting multiple options vary in different operating systems and browsers: For windows: Hold down the control (ctrl) button to select multiple options. For Mac: Hold down the command button to select multiple options.

Which attributes allows the user of ion-select to select not only one choice but any choices?

By adding the multiple attribute to select, users are able to select multiple options.

How do I select multiple options in a selection box in HTML?

To select multiple items, the user has to hold down the shift or ctrl key, then select with the mouse. That's not all you can do with the select and <option> tags. You can also make a multi-layer select box with the <optgroup> element inside a <select> tag.

How do I select default value in dropdown in ionic?

If you deal with default value xor objects, the cleanest way is to provide a compare function to the [compareWith] attribute. This function takes 2 objects in parameters and returns true if they are equals. This way, existing values in model will be selected at start.


3 Answers

You are missing the value attribute in select option, because when you select option it will reflect to the ng-model.Additionally to select multiple you need to add multiple attribute in your select.

Markup

<select ng-model="selectedValues" multiple>
    <option ng-repeat="option in options" value="{{option.value}}">{{option.name}}</option>
</select>
{{selectedValues}}
like image 167
Pankaj Parkar Avatar answered Oct 19 '22 06:10

Pankaj Parkar


Just add the multiple attribute in the select field.

<div class="list">
    <label class="item item-input item-select">
   <div class="input-label">
       Lightsaber
   </div>
   <select multiple="multiple">
        <option>Blue</option>
        <option selected>Green</option>
        <option>Red</option>
   </select>
</label>

like image 2
Danish Bhayani Avatar answered Oct 19 '22 07:10

Danish Bhayani


use ng-options to bind data, here is how

in the controller

$scope.values=  [
   {id:1, name:"value1" }, 
   {id:2, name:"value2" }, 
   {id:3, name:"value3" }
   ];
$scope.selectedValues= []; //initial selections

and in the view

<label class="item item-input item-select">

     <select multiple ng-model='selectedValues'
                    ng-options="a.name for a in values" >
     </select>
</label>
{{selectedValues}} <!-- to preview the selection -->
like image 1
Mohamed Ali Avatar answered Oct 19 '22 05:10

Mohamed Ali