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

后端 未结 4 1915
借酒劲吻你
借酒劲吻你 2020-12-30 23:52

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

相关标签:
4条回答
  • 2020-12-31 00:19

    You can disable tags by removing tags: true when initializing Select2. Or alternatively, setting tags: false when initializing Select2. Tags are only enabled if the tags option is truthy, which it is when you are passing in true.

    0 讨论(0)
  • 2020-12-31 00:29

    I am not sure if I should add the following in here but as I was searching for the same issue google pointed me to this question. However I use an older version 3.x and this is how to achieve the same scenario for the 3.x versions.

    Tested on version 3.5

    createSearchChoice: function(params) {
        return undefined;
    }
    
    0 讨论(0)
  • 2020-12-31 00:32

    I've been struggling with this as well, but got it working after a few hours.

    I had specified a few token seperators (because my visitors are allowed to create tags in a different spot in the website). Turns out the seperators are still applied even if the tags configuration is set to false.

    Solution: tags: false and do NOT add a value for tokenSeperators. Keep multiple: true.

    0 讨论(0)
  • 2020-12-31 00:35

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

    createTag: function(params) {
                    return undefined;
               }
    
    0 讨论(0)
提交回复
热议问题