Skip to content

Commit 1e1d908

Browse files
author
Brian Feister
committed
Merge pull request angular-ui#969 from brianfeister/master
Make angular-ui#840 merge-ready
2 parents bb3bfdf + 5b3b0ec commit 1e1d908

9 files changed

+181
-16
lines changed

dist/select.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,4 @@ body > .ui-select-bootstrap.open {
218218
/* Mark invalid Bootstrap */
219219
.ui-select-bootstrap.ng-dirty.ng-invalid > button.btn.ui-select-match {
220220
border-color: #D44950;
221-
}
221+
}

dist/select.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88

9-
(function () {
9+
(function () {
1010
"use strict";
1111

1212
var KEY = {
@@ -279,7 +279,7 @@ uis.controller('uiSelectCtrl',
279279
if (ctrl.searchInput.length !== 1) {
280280
throw uiSelectMinErr('searchInput', "Expected 1 input.ui-select-search but got '{0}'.", ctrl.searchInput.length);
281281
}
282-
282+
283283
ctrl.isEmpty = function() {
284284
return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === '';
285285
};
@@ -752,7 +752,7 @@ uis.directive('uiSelect',
752752
if (angular.isDefined(tAttrs.multiple))
753753
tElement.append("<ui-select-multiple/>").removeAttr('multiple');
754754
else
755-
tElement.append("<ui-select-single/>");
755+
tElement.append("<ui-select-single/>");
756756

757757
return function(scope, element, attrs, ctrls, transcludeFn) {
758758

@@ -774,7 +774,7 @@ uis.directive('uiSelect',
774774

775775
$select.onSelectCallback = $parse(attrs.onSelect);
776776
$select.onRemoveCallback = $parse(attrs.onRemove);
777-
777+
778778
//Set reference to ngModel from uiSelectCtrl
779779
$select.ngModel = ngModel;
780780

@@ -1028,7 +1028,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
10281028
$select = $scope.$select,
10291029
ngModel;
10301030

1031-
//Wait for link fn to inject it
1031+
//Wait for link fn to inject it
10321032
$scope.$evalAsync(function(){ ngModel = $scope.ngModel; });
10331033

10341034
ctrl.activeMatchIndex = -1;
@@ -1040,7 +1040,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
10401040

10411041
ctrl.refreshComponent = function(){
10421042
//Remove already selected items
1043-
//e.g. When user clicks on a selection, the selected array changes and
1043+
//e.g. When user clicks on a selection, the selected array changes and
10441044
//the dropdown should remove that item
10451045
$select.refreshItems();
10461046
$select.sizeSearchInput();
@@ -1139,7 +1139,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
11391139
};
11401140
if (!inputValue) return resultMultiple; //If ngModel was undefined
11411141
for (var k = inputValue.length - 1; k >= 0; k--) {
1142-
//Check model array of currently selected items
1142+
//Check model array of currently selected items
11431143
if (!checkFnMultiple($select.selected, inputValue[k])){
11441144
//Check model array of all items available
11451145
if (!checkFnMultiple(data, inputValue[k])){
@@ -1150,8 +1150,8 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
11501150
}
11511151
return resultMultiple;
11521152
});
1153-
1154-
//Watch for external model changes
1153+
1154+
//Watch for external model changes
11551155
scope.$watchCollection(function(){ return ngModel.$modelValue; }, function(newValue, oldValue) {
11561156
if (oldValue != newValue){
11571157
ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters
@@ -1743,4 +1743,4 @@ $templateCache.put("select2/select-multiple.tpl.html","<div class=\"ui-select-co
17431743
$templateCache.put("select2/select.tpl.html","<div class=\"ui-select-container select2 select2-container\" ng-class=\"{\'select2-container-active select2-dropdown-open open\': $select.open, \'select2-container-disabled\': $select.disabled, \'select2-container-active\': $select.focus, \'select2-allowclear\': $select.allowClear && !$select.isEmpty()}\"><div class=\"ui-select-match\"></div><div class=\"select2-drop select2-with-searchbox select2-drop-active\" ng-class=\"{\'select2-display-none\': !$select.open}\"><div class=\"select2-search\" ng-show=\"$select.searchEnabled\"><input type=\"text\" autocomplete=\"off\" autocorrect=\"off\" autocapitalize=\"off\" spellcheck=\"false\" role=\"combobox\" aria-expanded=\"true\" aria-owns=\"ui-select-choices-{{ $select.generatedId }}\" aria-label=\"{{ $select.baseTitle }}\" aria-activedescendant=\"ui-select-choices-row-{{ $select.generatedId }}-{{ $select.activeIndex }}\" class=\"ui-select-search select2-input\" ng-model=\"$select.search\"></div><div class=\"ui-select-choices\"></div></div></div>");
17441744
$templateCache.put("selectize/choices.tpl.html","<div ng-show=\"$select.open\" class=\"ui-select-choices selectize-dropdown single\"><div class=\"ui-select-choices-content selectize-dropdown-content\"><div class=\"ui-select-choices-group optgroup\" role=\"listbox\"><div ng-show=\"$select.isGrouped\" class=\"ui-select-choices-group-label optgroup-header\" ng-bind=\"$group.name\"></div><div role=\"option\" class=\"ui-select-choices-row\" ng-class=\"{active: $select.isActive(this), disabled: $select.isDisabled(this)}\"><div class=\"option ui-select-choices-row-inner\" data-selectable=\"\"></div></div></div></div></div>");
17451745
$templateCache.put("selectize/match.tpl.html","<div ng-hide=\"($select.open || $select.isEmpty())\" class=\"ui-select-match\" ng-transclude=\"\"></div>");
1746-
$templateCache.put("selectize/select.tpl.html","<div class=\"ui-select-container selectize-control single\" ng-class=\"{\'open\': $select.open}\"><div class=\"selectize-input\" ng-class=\"{\'focus\': $select.open, \'disabled\': $select.disabled, \'selectize-focus\' : $select.focus}\" ng-click=\"$select.activate()\"><div class=\"ui-select-match\"></div><input type=\"text\" autocomplete=\"off\" tabindex=\"-1\" class=\"ui-select-search ui-select-toggle\" ng-click=\"$select.toggle($event)\" placeholder=\"{{$select.placeholder}}\" ng-model=\"$select.search\" ng-hide=\"!$select.searchEnabled || ($select.selected && !$select.open)\" ng-disabled=\"$select.disabled\" aria-label=\"{{ $select.baseTitle }}\"></div><div class=\"ui-select-choices\"></div></div>");}]);
1746+
$templateCache.put("selectize/select.tpl.html","<div class=\"ui-select-container selectize-control single\" ng-class=\"{\'open\': $select.open}\"><div class=\"selectize-input\" ng-class=\"{\'focus\': $select.open, \'disabled\': $select.disabled, \'selectize-focus\' : $select.focus}\" ng-click=\"$select.activate()\"><div class=\"ui-select-match\"></div><input type=\"text\" autocomplete=\"off\" tabindex=\"-1\" class=\"ui-select-search ui-select-toggle\" ng-click=\"$select.toggle($event)\" placeholder=\"{{$select.placeholder}}\" ng-model=\"$select.search\" ng-hide=\"!$select.searchEnabled || ($select.selected && !$select.open)\" ng-disabled=\"$select.disabled\" aria-label=\"{{ $select.baseTitle }}\"></div><div class=\"ui-select-choices\"></div></div>");}]);

dist/select.min.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/select.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/demo-groupfilter.html

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<!DOCTYPE html>
2+
<html lang="en" ng-app="demo">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>AngularJS ui-select</title>
6+
7+
<!--
8+
IE8 support, see AngularJS Internet Explorer Compatibility http://docs.angularjs.org/guide/ie
9+
For Firefox 3.6, you will also need to include jQuery and ECMAScript 5 shim
10+
-->
11+
<!--[if lt IE 9]>
12+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.js"></script>
13+
<script src="http://cdnjs.cloudflare.com/ajax/libs/es5-shim/2.2.0/es5-shim.js"></script>
14+
<script>
15+
document.createElement('ui-select');
16+
document.createElement('ui-select-match');
17+
document.createElement('ui-select-choices');
18+
</script>
19+
<![endif]-->
20+
21+
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.18/angular.js"></script>
22+
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.18/angular-sanitize.js"></script>
23+
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.css">
24+
25+
<!-- ui-select files -->
26+
<script src="../dist/select.js"></script>
27+
<link rel="stylesheet" href="../dist/select.css">
28+
29+
<script src="demo.js"></script>
30+
31+
<!-- Select2 theme -->
32+
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/select2/3.4.5/select2.css">
33+
34+
<!--
35+
Selectize theme
36+
Less versions are available at https://github.com/brianreavis/selectize.js/tree/master/dist/less
37+
-->
38+
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.8.5/css/selectize.default.css">
39+
<!-- <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.8.5/css/selectize.bootstrap2.css"> -->
40+
<!-- <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.8.5/css/selectize.bootstrap3.css"> -->
41+
42+
<style>
43+
body {
44+
padding: 15px;
45+
}
46+
47+
.select2 > .select2-choice.ui-select-match {
48+
/* Because of the inclusion of Bootstrap */
49+
height: 29px;
50+
}
51+
52+
.selectize-control > .selectize-dropdown {
53+
top: 36px;
54+
}
55+
</style>
56+
</head>
57+
58+
<body ng-controller="DemoCtrl">
59+
<script src="demo.js"></script>
60+
61+
<button class="btn btn-default btn-xs" ng-click="enable()">Enable ui-select</button>
62+
<button class="btn btn-default btn-xs" ng-click="disable()">Disable ui-select</button>
63+
<button class="btn btn-default btn-xs" ng-click="clear()">Clear ng-model</button>
64+
65+
<h3>Select2 theme</h3>
66+
<p>Selected: {{country.selected}}</p>
67+
68+
69+
<h2> Filter groups by array (group-filter="['Z','B','C']")</h2>
70+
<ui-select ng-model="country.selected" theme="select2" ng-disabled="disabled" style="width: 300px;" title="Choose a country">
71+
<ui-select-match placeholder="Select or search a country in the list...">{{$select.selected.name}}</ui-select-match>
72+
<ui-select-choices group-by="firstLetterGroupFn" group-filter="['Z','B','C']" repeat="country in countries | filter: $select.search">
73+
<span ng-bind-html="country.name | highlight: $select.search"></span>
74+
<small ng-bind-html="country.code | highlight: $select.search"></small>
75+
</ui-select-choices>
76+
</ui-select>
77+
78+
<h2> Filter groups using a function (group-filter="reverseOrderFilterFn")</h2>
79+
<ui-select ng-model="country.selected" theme="select2" ng-disabled="disabled" style="width: 300px;" title="Choose a country">
80+
<ui-select-match placeholder="Select or search a country in the list...">{{$select.selected.name}}</ui-select-match>
81+
<ui-select-choices group-by="firstLetterGroupFn" group-filter="reverseOrderFilterFn" repeat="country in countries | filter: $select.search">
82+
<span ng-bind-html="country.name | highlight: $select.search"></span>
83+
<small ng-bind-html="country.code | highlight: $select.search"></small>
84+
</ui-select-choices>
85+
</ui-select>
86+
87+
88+
</body>
89+
</html>

examples/demo.js

+8
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ app.controller('DemoCtrl', function($scope, $http, $timeout, $interval) {
7979

8080
};
8181

82+
$scope.firstLetterGroupFn = function (item){
83+
return item.name[0];
84+
};
85+
86+
$scope.reverseOrderFilterFn = function(groups) {
87+
return groups.reverse();
88+
};
89+
8290
$scope.personAsync = {selected : "[email protected]"};
8391
$scope.peopleAsync = [];
8492

src/uiSelectChoicesDirective.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ uis.directive('uiSelectChoices',
2121

2222
// var repeat = RepeatParser.parse(attrs.repeat);
2323
var groupByExp = attrs.groupBy;
24+
var groupFilterExp = attrs.groupFilter;
2425

25-
$select.parseRepeatAttr(attrs.repeat, groupByExp); //Result ready at $select.parserResult
26+
$select.parseRepeatAttr(attrs.repeat, groupByExp, groupFilterExp); //Result ready at $select.parserResult
2627

2728
$select.disableChoiceExpression = attrs.uiDisableChoice;
2829
$select.onHighlightCallback = attrs.onHighlight;

src/uiSelectController.js

+22-2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ uis.controller('uiSelectCtrl',
5959
}
6060
}
6161

62+
function _groupsFilter(groups, groupNames) {
63+
var i, j, result = [];
64+
for(i = 0; i < groupNames.length ;i++){
65+
for(j = 0; j < groups.length ;j++){
66+
if(groups[j].name == [groupNames[i]]){
67+
result.push(groups[j]);
68+
}
69+
}
70+
}
71+
return result;
72+
}
73+
6274
// When the user clicks on ui-select, displays the dropdown list
6375
ctrl.activate = function(initSearchValue, avoidReset) {
6476
if (!ctrl.disabled && !ctrl.open) {
@@ -90,11 +102,11 @@ uis.controller('uiSelectCtrl',
90102
})[0];
91103
};
92104

93-
ctrl.parseRepeatAttr = function(repeatAttr, groupByExp) {
105+
ctrl.parseRepeatAttr = function(repeatAttr, groupByExp, groupFilterExp) {
94106
function updateGroups(items) {
107+
var groupFn = $scope.$eval(groupByExp);
95108
ctrl.groups = [];
96109
angular.forEach(items, function(item) {
97-
var groupFn = $scope.$eval(groupByExp);
98110
var groupName = angular.isFunction(groupFn) ? groupFn(item) : item[groupFn];
99111
var group = ctrl.findGroupByName(groupName);
100112
if(group) {
@@ -104,6 +116,14 @@ uis.controller('uiSelectCtrl',
104116
ctrl.groups.push({name: groupName, items: [item]});
105117
}
106118
});
119+
if(groupFilterExp){
120+
var groupFilterFn = $scope.$eval(groupFilterExp);
121+
if( angular.isFunction(groupFilterFn)){
122+
ctrl.groups = groupFilterFn(ctrl.groups);
123+
} else if(angular.isArray(groupFilterFn)){
124+
ctrl.groups = _groupsFilter(ctrl.groups, groupFilterFn);
125+
}
126+
}
107127
ctrl.items = [];
108128
ctrl.groups.forEach(function(group) {
109129
ctrl.items = ctrl.items.concat(group.items);

0 commit comments

Comments
 (0)