bootstrap-multiselect
bootstrap-multiselect copied to clipboard
When I use single-select mode, the enableCollapsibleOptGroups doesn't work
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.
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?
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.
(4) Make sure not using with enableClickableOptGroups
& includeSelectAllOption
. I got the outcome like this :
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 Thank you so much and it definitely helps a lot
@ck7300373 Thank you, you've really helped me a lot
@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.
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
@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.
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?