1
0
mirror of synced 2025-02-09 16:49:24 +03:00

Added createTag code samples

This lays down part of the path for
https://github.com/select2/select2/issues/4023 as well as
https://github.com/select2/select2/issues/3974.
This commit is contained in:
Kevin Brown 2016-05-26 20:50:12 -04:00
parent 7eab29e271
commit 8bc4f5d41d

View File

@ -19,18 +19,57 @@ $('select').select2({
Does tagging work with a single select?
</h3>
<p>
Yes.
</p>
{% include options/not-written.html %}
<h3>
How do I add extra properties to the tag?
</h3>
{% 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 %}
<h3>
Can I control when tags are created?
</h3>
{% 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 %}
<h3>