davidstutz / bootstrap-multiselect

JQuery multiselect plugin based on Twitter Bootstrap.
https://davidstutz.github.io/bootstrap-multiselect/
Other
3.67k stars 1.98k forks source link

Handle duplicate items #1093

Open mick88 opened 5 years ago

mick88 commented 5 years ago

The library does not seem to be handling duplicate items in the list very well. Duplicate items are treated like the same items and ticking both items does not increment selection count. Un-ticking any of selected items removes both from the button.

My use-case for having duplicate items is with opt-groups, where item can belong to multiple groups.

Working example: https://jsbin.com/jisalukiyo

Example code:

<html lang="en">
<head>
    <meta charset="UTF-8">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.15/css/bootstrap-multiselect.css" rel="stylesheet">
</head>
<body>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.15/js/bootstrap-multiselect.min.js"></script>

    <script type="text/javascript">
        $(document).ready(function() {
            $('select').multiselect();
        });
    </script>
    <div class="btn-group">
        <select multiple="multiple">
            <optgroup label="Group 1">
                <option value="1">Option 1</option>
            </optgroup>
            <optgroup label="Group 2">
                <option value="2">Option 2</option>
            </optgroup>
            <optgroup label="Everyone">
                <option value="1">Option 1</option>
                <option value="2">Option 2</option>
            </optgroup>
        </select>
    </div>
</body>
</html>
Mowd commented 5 years ago

I have the same problem, The workaround is assign different value of each option for now.