d-man
d-man

Reputation: 58083

Jquery bootstrap multiselect optgroup selection

I am using Jquery bootstrap multiselect plugin which seems pretty good and fulfill most of the requirements which i needed.

The only additional functionality i want is to add checkbox to OptGroup so if user wants to select complete group they can select all by clicking it.

any help appreciated.

http://davidstutz.github.io/bootstrap-multiselect/#examples

enter image description here

Upvotes: 3

Views: 27375

Answers (5)

naxxateux
naxxateux

Reputation: 133

You can use event.stopPropagation();

Upvotes: 4

Junip Dewan
Junip Dewan

Reputation: 859

in your code put this line of code only

enableClickableOptGroups: true

this will enable the option to select group

http://davidstutz.de/bootstrap-multiselect/#getting-started

Upvotes: 0

AsgarAli
AsgarAli

Reputation: 2211

No need to do any code to achieve your requirement.

There is an option called enableClickableOptGroups in this plugin to select all options of optgroup

http://davidstutz.github.io/bootstrap-multiselect/#configuration-options-enableClickableOptGroups

Upvotes: 6

Andreea Hash
Andreea Hash

Reputation: 41

After I checked an option group and then unchecked it, if I wanted to check it again, it would check all options from the group, but the group remained unchecked.

In order for the option group to be properly displayed as checked/unchecked after several retries, replace:

$(this).parent().find('input').**attr**('checked', checkAll);

with

$(this).parent().find('input').**prop**('checked', checkAll);

Upvotes: 1

PatrickDelancy
PatrickDelancy

Reputation: 66

Try something like this:

$('.multiselect-group').before('<input type="checkbox" />');
$(document).on('click', '.multiselect-group', function(event) {
    var checkAll = true;
    var $opts = $(this).parent().nextUntil(':has(.multiselect-group)'); 
    var $inactive = $opts.filter(':not(.active)'); 
    var $toggleMe = $inactive;
    if ($inactive.length == 0) { 
        $toggleMe = $opts;
        checkAll = false;
    }
    $toggleMe.find('input').click();
    $(this).parent().find('input').attr('checked', checkAll);
    event.preventDefault();
});

Upvotes: 5

Related Questions