Skip to content

Commit

Permalink
Fix #849 Use inputs instead of menu for checked state (#850)
Browse files Browse the repository at this point in the history
Filter the cached labels to exclude the search input.
  • Loading branch information
Michael committed Jun 4, 2019
1 parent 4c85dad commit 4e1d10a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/js/widget.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/jquery.multiselect.filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
$element.on('multiselectbeforeclose', $.proxy(this._reset, this));
}

var $label = $(document.createElement('label')).text(opts.label).append(this.$input);
var $label = $(document.createElement('label')).text(opts.label).append(this.$input).addClass('ui-multiselect-filter-label');
this.$wrapper = $(document.createElement('div'))
.addClass(filterClass)
.append($label)
Expand Down
6 changes: 3 additions & 3 deletions src/jquery.multiselect.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@
this.$checkboxes = this.$menu.children('.ui-multiselect-checkboxes');

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

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

/**
* Provides a list of all options that are not checked
* @returns {array} list of inputs
*/
getUnchecked: function() {
return this.$menu.find('input:not(:checked)');
return this.$inputs.filter(":not(:checked)");
},

/**
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@
assert.ok( input.is(":visible"), "Filter input box is visible" );
});

QUnit.test("checked and unchecked", function(assert) {
var labelCount = el.multiselect("getLabels").length
var uncheckedCount = el.multiselect("getUnchecked").length
var checkedCount = el.multiselect("getChecked").length
assert.equal(uncheckedCount, labelCount, "Only the ten options are returned");
assert.equal(uncheckedCount + checkedCount, labelCount, "Unchecked + checked should equal total inputs")
el.multiselect("refresh");
assert.equal(el.multiselect("getUnchecked").length, uncheckedCount, "Search input still excluded after refresh")
});

QUnit.test("filtering by node text", function(assert){
searchTest( "bbaa", 2);
searchTest( "bbaarr", 1);
Expand Down

0 comments on commit 4e1d10a

Please sign in to comment.