Search code examples
javascriptjqueryhtmltwitter-bootstrapbootstrap-multiselect

Bootstrap Multiselect plugin fails to uncheck all elements


I am using Bootstrap Multiselect plugin for my select option elements. When user select one (or all options) from one select option element, all elements from other select options element needs to be unchecked. I checked documents for solution and when I use code in documentation I got error:

bootstrap-multiselect.js:1042 (Uncaught TypeError: undefined is not a function)

Does someone knows where's the problem?

Here is my code:

 $('#select1').multiselect({
        includeSelectAllOption: true,
        enableFiltering: true,
        onChange: function(element, checked) {
            //alert ("OK");//Alerts pop ups
            $('#select2').multiselect('deselectAll', false);
            $('#select2').multiselect('updateButtonText')

        }
    });

Solution

  • I tried to recreate your issue by removing jQuery and bootstrap. Since all bootstrap really does is style it you can use the plugin without it (it just looks really bad) and it will not throw any errors.

    Removing jQuery will throw the following errors:

    Uncaught TypeError: Cannot read property 'fn' of undefined
    index.js:1 Uncaught ReferenceError: $ is not defined
    

    I looked at the latest version of bootstrap-multiselect.js and the 1402 line is blank so I do not know where that error is coming from.

    Line 1401 is:

    }(window.jQuery);
    

    My guess is you are using an older version of the plugin although that is probably not causing the issue. Try updating the plugin to see if that does anything.

    Please note I tested this on jQuery 2.1.3 using the latest version of bootstrap-multiselect on Chrome v41 Mac OSX 10.10