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.

{% img /media/select2-jquery/bloganizer-tags.jpg %}

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.

$(".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
			};
		}
	}
});
post by Kelt Dockins on 07/10/2013