Search code examples
jqueryjquery-select2-4

How to disable creating new tags with select2 v4.0?


I've been trying out the new Select2 v4.0 which has a lot of improvements. I'm mainly interested in the tags feature. I want to be able to search for tags via ajax and only be able to select a tag from the shown results and not be able to create new tags. The functionality is similar to StackOverflow - if you don't have the necessary reputation you can't create new tags, but you can still tag a question with existing tags.

Here's a jsfiddle with my code which is taken from the examples. In the example, you can create new tags which are what I want to limit. The user should be able to select tags only from the list that's retrieved from GitHub via ajax.

Does anybody know how to disable this functionality?


Solution

  • This should work - in the initialization of select2, try returning undefined from the createTag function like so:

    createTag: function(params) {
                    return undefined;
               }