如何禁用使用select2 v4.0创建新标签? [英] How to disable creating new tags with select2 v4.0?

查看:127
本文介绍了如何禁用使用select2 v4.0创建新标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试新的 Select2 v4.0 很多改进.我主要对tags功能感兴趣.我希望能够通过ajax搜索标签,并且能够从显示的结果中选择标签,而不能创建新标签.该功能类似于StackOverflow-如果您没有必要的声誉,则无法创建新标签,但仍可以使用现有标签来标记问题.

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.

这是一个 jsfiddle ,其中包含我的示例代码.在示例中,您可以创建我要限制的新标签.用户应该只能从通过ajax从GitHub检索的列表中选择标签.

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?

推荐答案

这应该起作用-在select2的初始化中,尝试从createTag函数返回未定义,如下所示:

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

createTag: function(params) {
                return undefined;
           }

这篇关于如何禁用使用select2 v4.0创建新标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆