Skip to content

Commit

Permalink
when filtering plugin is used and an optgroup label is clicked, selec…
Browse files Browse the repository at this point in the history
…t the underlying option tags. fixes #50
  • Loading branch information
ehynds committed Dec 14, 2010
1 parent b23ff7e commit c2debd3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
30 changes: 21 additions & 9 deletions src/jquery.multiselect.filter.js
Expand Up @@ -60,18 +60,30 @@
// rewrite internal _toggleChecked fn so that when checkAll/uncheckAll is fired,
// only the currently filtered elements are checked
instance._toggleChecked = function(flag, group){
var $inputs = (group && group.length)
? group
: this.labels.find('input'),
var $inputs = (group && group.length) ?
group :
this.labels.find('input'),

// do not include hidden elems if the menu isn't open.
selector = self.instance._isOpen
? ":disabled, :hidden"
: ":disabled";

$inputs.not( selector ).attr('checked', (flag ? 'checked' : ''));
selector = self.instance._isOpen ?
":disabled, :hidden" :
":disabled";

// toggle checked
$inputs.not( selector ).attr('checked', flag);

// update text
this.update();
this.element.children().not('disabled').attr('selected', (flag ? 'selected' : ''));

// figure out which option tags need to be selected
var values = $inputs.map(function(){
return this.value;
}).get();

// select option tags
this.element.find('option').filter(function(){
return !this.disabled && $.inArray(this.value, values) > -1;
}).attr({ 'selected':flag, 'aria-selected':flag });
};
},

Expand Down
9 changes: 3 additions & 6 deletions src/jquery.multiselect.js
Expand Up @@ -385,12 +385,9 @@ $.widget("ech.multiselect", {
}).get();

// toggle state on original option tags
this.element
.find('option')
.filter(function(){
return !this.disabled && $.inArray(this.value, values) > -1;
})
.attr({ 'selected':flag, 'aria-selected':flag });
this.element.find('option').filter(function(){
return !this.disabled && $.inArray(this.value, values) > -1;
}).attr({ 'selected':flag, 'aria-selected':flag });
},

_toggleDisabled: function( flag ){
Expand Down

0 comments on commit c2debd3

Please sign in to comment.