Can options be created based on the search term?

How do I enable tagging?

{% highlight js linenos %} $('select').select2({ tags: true }); {% endhighlight %} {% include options/not-written.html %}

Does tagging work with a single select?

Yes.

{% include options/not-written.html %}

How do I add extra properties to the tag?

{% highlight js linenos %} $('select').select2({ createTag: function (params) { var term = $.trim(params.term); if (term === '') { return null; } return { id: term, text: term, newTag: true // add additional parameters } } }); {% endhighlight %} {% include options/not-written.html %}

Can I control when tags are created?

{% highlight js linenos %} $('select').select2({ createTag: function (params) { // Don't offset to create a tag if there is no @ symbol if (params.term.indexOf('@') === -1) { // Return null to disable tag creation return null; } return { id: params.term, text: params.term } } }); {% endhighlight %} {% include options/not-written.html %}

How do I control the placement of the option?

{% highlight js linenos %} $('select').select2({ insertTag: function (data, tag) { // Insert the tag at the end of the results data.push(tag); } }); {% endhighlight %} {% include options/not-written.html %}