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

Commit 64b6ab1

Browse files
committed
Add new directive for select header with groupBy
1 parent 5dfabd4 commit 64b6ab1

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

src/common.css

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ body > .select2-container.open {
127127
width: 0;
128128
}
129129

130+
.ui-select-container[theme="selectize"] .ui-select-header-group-selectable:hover {
131+
background-color: #f5f5f5;
132+
}
133+
134+
.ui-select-container[theme="selectize"] .ui-select-header-group-selectable {
135+
cursor: pointer;
136+
padding-left: 15px;
137+
}
138+
130139
/* Bootstrap theme */
131140

132141
/* Helper class to show styles when focus */
@@ -253,6 +262,16 @@ body > .ui-select-bootstrap.open {
253262
border-right: 1px solid #428bca;
254263
}
255264

265+
.ui-select-bootstrap .ui-select-header-group-selectable:hover {
266+
background-color: #f5f5f5;
267+
}
268+
269+
.ui-select-bootstrap .ui-select-header-group-selectable {
270+
color: black;
271+
cursor: pointer;
272+
padding: 3px 10px;
273+
}
274+
256275
.ui-select-bootstrap .ui-select-choices-row>span {
257276
cursor: pointer;
258277
display: block;

src/uiSelectController.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,12 @@ uis.controller('uiSelectCtrl',
166166
ctrl.searchInput[0].focus();
167167
};
168168

169-
ctrl.findGroupByName = function(name) {
169+
ctrl.findGroupByName = function(name, noStrict) {
170170
return ctrl.groups && ctrl.groups.filter(function(group) {
171-
return group.name === name;
171+
if (noStrict)
172+
return group.name == name;
173+
else
174+
return group.name === name;
172175
})[0];
173176
};
174177

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
uis.directive('uiSelectHeaderGroupSelectable', ['$timeout', function($timeout) {
2+
return {
3+
restrict: 'EA',
4+
require: ['^uiSelect'],
5+
scope: true,
6+
link: function ($scope, $element, attrs, select) {
7+
// TODO Why that???
8+
var $select = select[0];
9+
10+
$scope.$watch('$select.groups', function() {
11+
if ($select.multiple && $select.groups) {
12+
var elements = $element.querySelectorAll('.ui-select-choices-group-label');
13+
14+
angular.forEach(elements, function(e) {
15+
var element = angular.element(e);
16+
17+
// Check the onClick event is not already listen
18+
if (!element.hasClass('ui-select-header-group-selectable')) {
19+
element.addClass('ui-select-header-group-selectable');
20+
21+
element.on('click', function () {
22+
// TODO It's the good way?
23+
var group = $select.findGroupByName(element.text(), true);
24+
25+
angular.forEach(group.items, function(item) {
26+
$timeout(function() {
27+
$select.select(item, false, ' ');
28+
});
29+
});
30+
});
31+
}
32+
});
33+
} else {
34+
console.error('Use uiSelectHeaderGroupSelectable with no multiple uiSelect or without groupBy');
35+
}
36+
});
37+
}
38+
};
39+
}]);

0 commit comments

Comments
 (0)