简体   繁体   中英

select2 maximumSelectionSize not working after removing element

I m using select2 plugin Version: 3.4.4 My problem with maximumSelectionSize of select2. i want to allow add custom tag to user so i used select2 with tags my code is

$('#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. and tags are dynamically data

try update again value of maximumSelectionSize in select2 like this

   $('#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
            });
        });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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