Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Semantic-UI Multiple selection get values

Based on Semantic-UI docs, https://semantic-ui.com/modules/dropdown.html#multiple-selections

I have following code inside angular2 template:

<select id="thickness" name="thick" [(ngModel)]="form.thickness" multiple="multiple" class="ui multiple dropdown selection">
     <option value="">Выбрать</option>
     <option value="100">100 mm</option>
     <option value="150">150 mm</option>
     <option value="200">200 mm</option>
     <option value="250">250 mm</option>
     <option value="300">300 mm</option>
     <option value="375">375 mm</option>
     <option value="400">400 mm</option>
</select>

I'd like to get array of selected values from Select to angular model form.thickness

However, I am getting empty array. inside ngOnInit I have $('#thickness').dropdown();

console.log($('#thickness').dropdown('get value')); gives empty array;

How to get values from dropdown multiple selection?

like image 624
Evgheny Kalkutin Avatar asked Mar 27 '17 09:03

Evgheny Kalkutin


2 Answers

Suggesting that your code looks like this:

<div class="ui multiple selection dropdown">
    <i class="dropdown icon"></i>
    <div class="default text">Tag Multiple Categories</div>
        <select multiple="" id="multi-select">
            <option value="">Categories</option>
            <option value="datastructure">Data Structure</option>
            <option value="stack">Stack</option>
            <option value="queue">Queue</option>
        </select>
    </div> 
</div>

the following will return an array of selected values:

$("#multi-select").dropdown("get value") 

Output:

["stack", "queue"]

Note:

Make sure not to have hidden input field in the html otherwise it returns a string value instead of array of values

like image 93
Supritha P Avatar answered Oct 31 '22 14:10

Supritha P


You can still use select. Here's how to do it in Aurelia: form.html:

<select id="thickness" name="thick"  multiple="" class="ui multiple dropdown selection" value.bind="thickness_selected">
     <option value="">Выбрать</option>
     <option value="100">100 mm</option>
     <option value="150">150 mm</option>
</select>

form.ts:

export class form {

    thickness_selected: number[] = [];

submit() {
        const self = this;
        for (let id of self.thickness_selected) {
            console.log(id);
        }
    }

}
like image 44
Programmer Avatar answered Oct 31 '22 13:10

Programmer