Reputation: 406
I need to create select2 where I can select multiple values. But I'm getting "no results found" message everytime, tried various solutions but nothing worked. I really don't have idea what's wrong.
<select id="keywords-input" multiple="multiple" style="width:300px">
{*
<option selected="selected" value="Val 1">Val 1</option>*} {*
<option selected="selected" value="Val 2">Val 2</option>*} {*
<option selected="selected" value="Val 3">Val 3</option>*} {*
<option selected="selected" value="Val 4">Val 4</option>*} {*
<option selected="selected" value="asfsafafsa">asfsafafsa</option>*}
</select>
<script>
$(document).ready(function() {
$('#keywords-input').select2({
tags: true,
tokenSeparators: [',', ' '],
data: ['Val1', 'Val2', 'Val3'],
maximumInputLength: 10,
multiple: true
});
});
</script>
Upvotes: 4
Views: 8284
Reputation: 406
It was caused by another javascript that used select2 class, now it works. So it my code wasn't wrong.
Upvotes: 6
Reputation: 878
Your code works just fine for me:
HTML
<select id="keywords-input" multiple="multiple" style="width:300px">
{*
<option selected="selected" value="Val 1">Val 1</option>*} {*
<option selected="selected" value="Val 2">Val 2</option>*} {*
<option selected="selected" value="Val 3">Val 3</option>*} {*
<option selected="selected" value="Val 4">Val 4</option>*} {*
<option selected="selected" value="asfsafafsa">asfsafafsa</option>*}
</select>
JS
$(document).ready(function() {
$('#keywords-input').select2({
tags: true,
maximumInputLength: 10,
});
});
Upvotes: 2