Select 2 jQuery (creating tags)

I wanted something to do tags for a project I’m working on, so I put together something quick with Select2 which (imo) is much more feature-rich than it’s sister plugin Chosen. I’ve not tried out tag-it so I can’t really comment on how well it works.

Here is some code to do tagging with select2. It’s actually pretty simple once you dig through their big ass wiki api and figure out how to do it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$(".taggy").select2(
{
tags: true,

tokenSeparators: [",", " "],

createSearchChoice: function(term, data)
{
if ($(data).filter(function() {
return this.text.localeCompare(term) === 0;
}).length === 0) {
return {
id: term,
text: term
};
}
}
});