Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery select2 breaks as soon as I add tags

As soon as I add tags to my jQuery select2 it breaks and reverts back to the normal HTML select box.

Here is my code (exactly like this example):

$(document).ready(function() {
    $("#tags").select2({tags:["red", "green", "blue"]});
});

If I remove the tags part it works again:

$(document).ready(function() {
    $("#tags").select2();
});
like image 546
Armandt Slabbert Avatar asked Jun 10 '14 17:06

Armandt Slabbert


2 Answers

If you look in your javascript console you will see the following error message:

Error: Option 'tags' is not allowed for Select2 when attached to a <select> element.

That means, when you want to use the 'tags' option, you have to apply it to an input:text element instead of a select.

JSFiddle with proof: http://jsfiddle.net/Y8Wc7/

like image 129
Roberto Linares Avatar answered Nov 19 '22 23:11

Roberto Linares


Select2 version 4.0.0 now allows tags to be attached to a <select>

like image 25
nitsujri Avatar answered Nov 19 '22 23:11

nitsujri