File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
docs/_includes/options/dropdown Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1919 Does tagging work with a single select?
2020 </ h3 >
2121
22+ < p >
23+ Yes.
24+ </ p >
25+
2226 {% include options/not-written.html %}
2327
2428 < h3 >
2529 How do I add extra properties to the tag?
2630 </ h3 >
2731
32+ {% highlight js linenos %}
33+ $('select').select2({
34+ createTag: function (params) {
35+ var term = $.trim(params.term);
36+
37+ if (term === '') {
38+ return null;
39+ }
40+
41+ return {
42+ id: term,
43+ text: term,
44+ newTag: true // add additional parameters
45+ }
46+ }
47+ });
48+ {% endhighlight %}
49+
2850 {% include options/not-written.html %}
2951
3052 < h3 >
3153 Can I control when tags are created?
3254 </ h3 >
3355
56+ {% highlight js linenos %}
57+ $('select').select2({
58+ createTag: function (params) {
59+ // Don't offset to create a tag if there is no @ symbol
60+ if (params.term.indexOf('@') === -1) {
61+ // Return null to disable tag creation
62+ return null;
63+ }
64+
65+ return {
66+ id: params.term,
67+ text: params.term
68+ }
69+ }
70+ });
71+ {% endhighlight %}
72+
3473 {% include options/not-written.html %}
3574
3675 < h3 >
You can’t perform that action at this time.
0 commit comments