Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collapsible Optgroups + Clickable optgroups #1181

Open
mikehobson opened this issue Feb 4, 2021 · 2 comments
Open

Collapsible Optgroups + Clickable optgroups #1181

mikehobson opened this issue Feb 4, 2021 · 2 comments

Comments

@mikehobson
Copy link

I am using Bootstrap multi-select for a list of countries and football leagues with those countries. I want the interface to be as easy as possible so I have enabled the following options

enableClickableOptGroups: true,
enableCollapsibleOptGroups: true,
collapseOptGroupsByDefault: true,

This works well as users can select individual leagues or click at a country level and select all leagues for that country in one go

I have created a JSfiddle here https://jsfiddle.net/mikehobson/w53c2vd8/8/

The only flaw is that if you click anywhere on the row except exactly on the down arrow it selects all the items in that optgroup, which from a user experience point of view isn't great. So for example, if I click to the far right of Albania in the same row in my example, it still selects all

I want the behaviour that if I click the check box only it selects all the options under the optgroup, if I click anywhere else on that row it expands it to show the items underneath but im not sure if this is possible or if I have done something wrong

@LucasRoquilly
Copy link

LucasRoquilly commented Sep 11, 2021

Hi,

I had the same exact problem and managed to find an easy fix. This bug is due to the <label> element triggering the checkbox when clicked. Quick way to fix it is by appending the checkbox to the <a> element and not nested in the <label> element.

In bootstrap-multiselect.js, I changed the line :
$('a label', $li).prepend('<input type="checkbox" value="' + value + '"/>');
by :
$('a', $li).prepend('<input type="checkbox" value="' + value + '"/>');

And for fixing the design, I changed the line :
$("li.multiselect-group > a > input", this.$ul).css('margin', '4px 0px 5px -20px');
by the line :
$("li.multiselect-group input", this.$ul).css('margin-left', '12px');

Hope it can help anyone !

@tiesont
Copy link
Collaborator

tiesont commented Sep 11, 2021

Hmm, it's a bit disconcerting that we build the template that way - form elements (input, select, textarea, buttons) really shouldn't be embedded in an anchor element, since interactive elements are not permitted (see MDN). I think we'll need to address that whenever we start updating for BS5 support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants