From 3d4c606aaa611cb70ec0a378b9eea8e7bf16ea10 Mon Sep 17 00:00:00 2001 From: Aaron McMillin Date: Mon, 19 Dec 2016 12:11:58 -0500 Subject: [PATCH 1/2] When source data has display:none, hide the options --- src/jquery.multiselect.filter.js | 4 +++- src/jquery.multiselect.js | 14 +++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/jquery.multiselect.filter.js b/src/jquery.multiselect.filter.js index df3bfbf..a525e45 100644 --- a/src/jquery.multiselect.filter.js +++ b/src/jquery.multiselect.filter.js @@ -164,11 +164,13 @@ }, 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 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 { From 54c1b5709214b7682ad9b5d8bca03a840cce4b61 Mon Sep 17 00:00:00 2001 From: Aaron McMillin Date: Mon, 16 Jan 2017 12:38:46 -0500 Subject: [PATCH 2/2] Also don't index hidden items inside optiongroups --- src/jquery.multiselect.filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jquery.multiselect.filter.js b/src/jquery.multiselect.filter.js index a525e45..3a7d6c9 100644 --- a/src/jquery.multiselect.filter.js +++ b/src/jquery.multiselect.filter.js @@ -175,7 +175,7 @@ // account for optgroups if(this.tagName.toLowerCase() === "optgroup") { - elem = elem.children(); + elem = elem.children(":not(:css(display=none))"); } return elem.map(function() {