Skip to content

Commit 4e1d10a

Browse files
author
Michael
authored
Fix #849 Use inputs instead of menu for checked state (#850)
Filter the cached labels to exclude the search input.
1 parent 4c85dad commit 4e1d10a

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

docs/js/widget.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/jquery.multiselect.filter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
$element.on('multiselectbeforeclose', $.proxy(this._reset, this));
104104
}
105105

106-
var $label = $(document.createElement('label')).text(opts.label).append(this.$input);
106+
var $label = $(document.createElement('label')).text(opts.label).append(this.$input).addClass('ui-multiselect-filter-label');
107107
this.$wrapper = $(document.createElement('div'))
108108
.addClass(filterClass)
109109
.append($label)

src/jquery.multiselect.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@
591591
this.$checkboxes = this.$menu.children('.ui-multiselect-checkboxes');
592592

593593
// Update saved labels and inputs
594-
this.$labels = this.$menu.find('label');
594+
this.$labels = this.$menu.find('label:not(.ui-multiselect-filter-label)');
595595
this.$inputs = this.$labels.children('input');
596596

597597
// If the filter widget is in use, then also update its cache.
@@ -1652,15 +1652,15 @@
16521652
* @returns {array} list of inputs
16531653
*/
16541654
getChecked: function() {
1655-
return this.$menu.find('input:checked');
1655+
return this.$inputs.filter(":checked");
16561656
},
16571657

16581658
/**
16591659
* Provides a list of all options that are not checked
16601660
* @returns {array} list of inputs
16611661
*/
16621662
getUnchecked: function() {
1663-
return this.$menu.find('input:not(:checked)');
1663+
return this.$inputs.filter(":not(:checked)");
16641664
},
16651665

16661666
/**

tests/unit/filter.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@
6464
assert.ok( input.is(":visible"), "Filter input box is visible" );
6565
});
6666

67+
QUnit.test("checked and unchecked", function(assert) {
68+
var labelCount = el.multiselect("getLabels").length
69+
var uncheckedCount = el.multiselect("getUnchecked").length
70+
var checkedCount = el.multiselect("getChecked").length
71+
assert.equal(uncheckedCount, labelCount, "Only the ten options are returned");
72+
assert.equal(uncheckedCount + checkedCount, labelCount, "Unchecked + checked should equal total inputs")
73+
el.multiselect("refresh");
74+
assert.equal(el.multiselect("getUnchecked").length, uncheckedCount, "Search input still excluded after refresh")
75+
});
76+
6777
QUnit.test("filtering by node text", function(assert){
6878
searchTest( "bbaa", 2);
6979
searchTest( "bbaarr", 1);

0 commit comments

Comments
 (0)