Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

fix(uiSelectHeaderGroupSelectableDirective): do not issue error if feature is disabled; apply selectable feature after options list changed/filtered; do not select unnamed group #2069

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 21 additions & 18 deletions src/uiSelectHeaderGroupSelectableDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,36 @@ uis.directive('uiSelectHeaderGroupSelectable', ['$timeout', function($timeout) {
if ($select.multiple && $select.groups) {
return $element.querySelectorAll('.ui-select-choices-group-label');
} else {
console.error('Use uiSelectHeaderGroupSelectable with no multiple uiSelect or without groupBy');
if(isEnabled()){
console.error('Use uiSelectHeaderGroupSelectable with no multiple uiSelect or without groupBy');
}
return [];
}
}

function enableClick() {
if (isEnabled()) {
angular.forEach(getElements(), function(e) {
var element = angular.element(e);
$timeout(function() {
angular.forEach(getElements(), function (e) {
var element = angular.element(e);

// Check the onClick event is not already listen
if (!element.hasClass('ui-select-header-group-selectable')) {
element.addClass('ui-select-header-group-selectable');
// Check the onClick event is not already listen
if (element.text() && !element.hasClass('ui-select-header-group-selectable')) {
element.addClass('ui-select-header-group-selectable');

element.on('click', function () {
if (isEnabled()) {
var group = $select.findGroupByName(element.text(), true);
element.on('click', function () {
if (isEnabled()) {
var group = $select.findGroupByName(element.text(), true);

angular.forEach(group.items, function(item) {
$timeout(function() {
$select.select(item, false, ' ');
angular.forEach(group.items, function (item) {
$timeout(function () {
$select.select(item, false, ' ');
});
});
});
}
});
}
}
});
}
});
});
}
}
Expand All @@ -69,9 +73,8 @@ uis.directive('uiSelectHeaderGroupSelectable', ['$timeout', function($timeout) {
}
});

$scope.$watch('$select.groups', enableClick);
$scope.$watch(function() {
return $select.selected && $select.selected.length ? $select.selected.length : -1;
return $select.groups && $select.groups.length ? $select.groups.length : -1;
}, enableClick);
}
};
Expand Down