diff --git a/src/jquery.multiselect.filter.js b/src/jquery.multiselect.filter.js index df3bfbf..3a7d6c9 100644 --- a/src/jquery.multiselect.filter.js +++ b/src/jquery.multiselect.filter.js @@ -164,16 +164,18 @@ }, updateCache: function() { + // each list item this.rows = this.instance.menu.find(".ui-multiselect-checkboxes li:not(.ui-multiselect-optgroup-label)"); // cache - this.cache = this.element.children().map(function() { + // Skip display-none rows + this.cache = this.element.children(":not(:css(display=none))").map(function() { var elem = $(this); // account for optgroups if(this.tagName.toLowerCase() === "optgroup") { - elem = elem.children(); + elem = elem.children(":not(:css(display=none))"); } return elem.map(function() { diff --git a/src/jquery.multiselect.js b/src/jquery.multiselect.js index 5c8eeb3..ac989f7 100644 --- a/src/jquery.multiselect.js +++ b/src/jquery.multiselect.js @@ -19,6 +19,12 @@ * */ (function($, undefined) { + // http://stackoverflow.com/a/3640212/401636 + // custom css filter ex: :css(display=none) + $.expr[':'].css = function(obj, index, meta, stack) { + var args = meta[3].split(/\s*=\s*/); + return $(obj).css(args[0]) == args[1]; + } var multiselectID = 0; var $doc = $(document); @@ -199,15 +205,17 @@ } } - //Turn all the options and optiongroups into list items - el.children().each(function(i) { + // Turn all the options and optiongroups into list items + // hide display=none options and optiongroups + el.children(":not(:css(display=none))").each(function(i) { var $this = $(this); if(this.tagName === 'OPTGROUP') { var $groupLabel = $("
  • ").addClass('ui-multiselect-optgroup-label ' + this.className).appendTo($dropdown); var $link = $("").attr("href", "#").text(this.getAttribute('label')).appendTo($groupLabel); - $this.children().each(function() { + // hide display=none options + $this.children(":not(:css(display=none))").each(function() { var $listItem = makeItem(this, true).appendTo($dropdown); }); } else {