bootstrap-multiselect icon indicating copy to clipboard operation
bootstrap-multiselect copied to clipboard

When I use single-select mode, the enableCollapsibleOptGroups doesn't work

Open zhouwe1 opened this issue 7 years ago • 8 comments

My code like this:

<select id="select-category">  
    <optgroup label="A">
        <option  name="out_types" value="a">aa</option>                                  
    </optgroup>
    <optgroup label="B">
        <option  name="out_types" value="b">bb</option>                                  
    </optgroup>
</select>

<script language="javascript">
        $(document).ready(function() {
            $('#select-category').multiselect({
                enableFiltering: true,
                dropUp: true,
                enableCollapsibleOptGroups: true,
                enableFiltering: true,
                maxHeight:500,
                enableCaseInsensitiveFiltering: true,
        });
</script>

When I add 'multiple="multiple"', the function is ok.

zhouwe1 avatar Sep 07 '17 03:09 zhouwe1

Having the same issue as well...

However according to the author, single select with enableCollapsibleOptGroups option is not supported, and maybe not either in the future?

vaddenz avatar Oct 15 '17 14:10 vaddenz

At first, thanks to David for making this power select plugin.

Try this little trick if U urgently need to implement a Collapsible Single-Select :

(1) open " bootstrap-multiselect.js " file, (2) find "enableCollapsibleOptGroups" string, U will find 2 IF statements as following : if (this.options.enableCollapsibleOptGroups && this.options.multiple ) { .......... etc.. }, this)); and if (this.options.enableCollapsibleOptGroups && this.options.multiple ) { $('a', $li).append('<span class="caret-container"><b class="caret"></b></span>'); }

(3) delete or comment out 2 "&& this.options.multiple" condition as below, and save the jS file. image

(4) Make sure not using with enableClickableOptGroups & includeSelectAllOption . I got the outcome like this : image

Don't know what good/bad else the modification will affect to your entire HTML project or stability~ So... Plz do it with caution.

ck7300373 avatar Oct 28 '17 07:10 ck7300373

@ck7300373 Thank you so much and it definitely helps a lot

vaddenz avatar Oct 28 '17 07:10 vaddenz

@ck7300373 Thank you, you've really helped me a lot

zhouwe1 avatar Nov 10 '17 09:11 zhouwe1

@ck7300373 thanks for the quick fix. I am actually not sure why we programmatically disabled collapislbe optgroups in single select mode. I will definitely add this to the FAQ and consider applying the fix.

davidstutz avatar Nov 23 '17 22:11 davidstutz

Hi, any updates on this topic. Can we have the a single select with enableClickableOptGroups without the fix ck7300373, I am using the latest v1.1.1.

Many thanks

vjorge avatar Jan 05 '22 09:01 vjorge

@ck7300373 thanks for the quick fix. I am actually not sure why we programmatically disabled collapislbe optgroups in single select mode. I will definitely add this to the FAQ and consider applying the fix.

Thanks, I just run into the same issue, would be great to have this option for single mode too, cheers.

markusd1984 avatar Nov 29 '22 12:11 markusd1984

enableCollapsibleOptGroups

Thanks the mod worked a treat, also works well with default collapsed collapseOptGroupsByDefault: true,.

Btw. how did you achieve the search / cancel icon in the search bar?

markusd1984 avatar Nov 29 '22 13:11 markusd1984