简体   繁体   English

select2 maximumSelectionSize删除元素后不起作用

[英]select2 maximumSelectionSize not working after removing element

I m using select2 plugin Version: 3.4.4 My problem with maximumSelectionSize of select2. 我正在使用select2插件版本:3.4.4 select2的maximumSelectionSize问题。 i want to allow add custom tag to user so i used select2 with tags my code is 我想允许向用户添加自定义标签,所以我将select2与标签一起使用,我的代码是

$('#color_group').select2({
    theme: "bootstrap",
    placeholder: "Select color Name",
    tags: ['red', 'blue'],
    maximumSelectionSize: 1
});

its working fine its allows user to add only 1 color but when user remove that color try to add some other color its say You can only select 1 item i don't know whats wrong with select2. 它的工作正常,它允许用户仅添加一种颜色,但是当用户删除该颜色时,尝试添加其他颜色,例如You can only select 1 item我不知道select2怎么了。 and tags are dynamically data 标签是动态数据

try update again value of maximumSelectionSize in select2 like this 尝试像这样在select2中再次更新maximumSelectionSize的值

   $('#color_group').select2({
        theme: "bootstrap",
        placeholder: "Select color Name",
        tags: ['red', 'blue'],
        maximumSelectionSize: 1
    });


   //add this code after above code and try    
    $('#color_group').on('change', function() {
            $('#color_group').select2({
                theme: "bootstrap",
                placeholder: "Select Group Name",
                tags: ['red', 'blue'],
                maximumSelectionSize: 1
            });
        });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM