bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

Radio button and checkbox items in dropdown menu

Open suigintou opened this issue 14 years ago • 8 comments

Please add styles for displaying radio buttons and checkboxes in dropdown menu.

suigintou avatar Feb 20 '12 08:02 suigintou

There should be no reason you cannot do that right now as the styles already exist in the forms section for a block of radios or checkboxes. The only problem you'll run into is clicks closing the dropdown menu, but we dont' currently support that.

mdo avatar Feb 20 '12 18:02 mdo

Here is my workaround for this:

I added the class "drop-menu-form" to the dropdown-menu so that you now have :

<ul class="dropdown-menu dropdown-menu-form">
    ... stuff here ...
</ul>

Then I added the following javascript

$('.dropdown-menu').on('click', function(e){
        if($(this).hasClass('dropdown-menu-form')){
            e.stopPropagation();
        }
});

ocrdeveloper avatar Sep 28 '12 16:09 ocrdeveloper

Another solution if you add the dropdown dynamically:

$(document).on("click", ".dropdown-multiselect", function (e) {
    var parent = $(this).parent(".btn-group");
    if (!parent.hasClass("open"))
        parent.addClass("open");
});

Vangi avatar Nov 30 '12 16:11 Vangi

In AngularJS, I worked around this by using ng-show/hide, and font awesome checkmarks to display checkboxes. Looks very nice. I'm not using a form for submit, so this won't work in that context.

    <ul class="dropdown-menu">
        <li>
            <a ng-click="filter.clearPartyFilter()" >
                <i class="icon icon-check-empty" ng-show="filter.partyFiltering"></i>
                <i class="icon icon-check-sign" ng-hide="filter.partyFiltering"></i>
                <strong>Show all parties</strong>
            </a>
        </li>
        ....
    </ul>    

stefaneg avatar Oct 16 '13 19:10 stefaneg

A slight improvement to above answers...

<ul class="dropdown-menu dropdown-menu-form">
  <li><label class="checkbox"><input type="checkbox">One</label></li>
  <li><label class="checkbox"><input type="checkbox">Two</label></li>
</ul>
// Allow Bootstrap dropdown menus to have forms/checkboxes inside, 
// and when clicking on a dropdown item, the menu doesn't disappear.
$(document).on('click', '.dropdown-menu.dropdown-menu-form', function(e) {
  e.stopPropagation();
});

philfreo avatar Feb 04 '14 02:02 philfreo

Any update on an official solution that does not require a workaround?

roman-ku avatar Aug 30 '16 17:08 roman-ku

I'm having a hard time getting these suggestions to work on mobile browsers fyi.

CopyJosh avatar May 05 '17 20:05 CopyJosh

Here is my workaround for this:

I added the class "drop-menu-form" to the dropdown-menu so that you now have :

<ul class="dropdown-menu dropdown-menu-form">
    ... stuff here ...
</ul>

Then I added the following javascript

$('.dropdown-menu').on('click', function(e){
        if($(this).hasClass('dropdown-menu-form')){
            e.stopPropagation();
        }
});

Thanks, it works well

Asmitta-01 avatar Mar 07 '22 10:03 Asmitta-01