jQuery select2 breaks as soon as I add tags
Asked Answered
A

2

5

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();
});
Adduce answered 10/6, 2014 at 17:6 Comment(2)
What is #tags a <div> or a <select> - it wont work for <select>Plater
Works for me jsfiddle.net/2Xt2uReggi
P
10

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/

Pulmotor answered 10/6, 2014 at 17:32 Comment(0)
A
8

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

Andry answered 29/4, 2015 at 2:51 Comment(2)
I am using select2 v4.0+ but still facing the same issue.Stuyvesant
Take a look at select2.org/taggingAndry

© 2022 - 2024 — McMap. All rights reserved.