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

Commit 3fac88c

Browse files
committed
Update examples, add new filter propsFilter
1 parent bb8f1dd commit 3fac88c

File tree

5 files changed

+53
-10
lines changed

5 files changed

+53
-10
lines changed

examples/bootstrap.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<!--
88
IE8 support, see AngularJS Internet Explorer Compatibility http://docs.angularjs.org/guide/ie
9-
For Firefox 3.6, you will need to include jQuery
9+
For Firefox 3.6, you will also need to include jQuery and ECMAScript 5 shim
1010
-->
1111
<!--[if lt IE 9]>
1212
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.js"></script>

examples/demo.html

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<!--
88
IE8 support, see AngularJS Internet Explorer Compatibility http://docs.angularjs.org/guide/ie
9-
For Firefox 3.6, you will need to include jQuery
9+
For Firefox 3.6, you will also need to include jQuery and ECMAScript 5 shim
1010
-->
1111
<!--[if lt IE 9]>
1212
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.js"></script>
@@ -64,18 +64,24 @@
6464

6565
<h3>Bootstrap theme</h3>
6666
<p>Selected: {{address.selected.formatted_address}}</p>
67-
<ui-select ng-model="address.selected" theme="bootstrap" ng-disabled="disabled" style="width: 300px;">
67+
<ui-select ng-model="address.selected"
68+
theme="bootstrap"
69+
ng-disabled="disabled"
70+
reset-search-input="false"
71+
style="width: 300px;">
6872
<match placeholder="Enter an address...">{{$select.selected.formatted_address}}</match>
69-
<choices repeat="address in getAddress($select.search) track by $index">
73+
<choices repeat="address in addresses track by $index"
74+
refresh="refreshAddresses($select.search)"
75+
refresh-delay="0">
7076
<div ng-bind-html="address.formatted_address | highlight: $select.search"></div>
7177
</choices>
7278
</ui-select>
7379

7480
<h3>Select2 theme</h3>
7581
<p>Selected: {{person.selected}}</p>
7682
<ui-select ng-model="person.selected" theme="select2" ng-disabled="disabled" style="min-width: 300px;">
77-
<match placeholder="Select a person in the list or search his *age*...">{{$select.selected.name}}</match>
78-
<choices repeat="person in people | filter: {age: $select.search}">
83+
<match placeholder="Select a person in the list or search his name/age...">{{$select.selected.name}}</match>
84+
<choices repeat="person in people | propsFilter: {name: $select.search, age: $select.search}">
7985
<div ng-bind-html="person.name | highlight: $select.search"></div>
8086
<small>
8187
email: {{person.email}}

examples/demo.js

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,43 @@
22

33
var app = angular.module('demo', ['ngSanitize', 'ui.select']);
44

5+
/**
6+
* AngularJS default filter with the following expression:
7+
* "person in people | filter: {name: $select.search, age: $select.search}"
8+
* performs a AND between 'name: $select.search' and 'age: $select.search'.
9+
* We want to perform a OR.
10+
*/
11+
app.filter('propsFilter', function() {
12+
return function(items, props) {
13+
var out = [];
14+
15+
if (angular.isArray(items)) {
16+
items.forEach(function(item) {
17+
var itemMatches = false;
18+
19+
var keys = Object.keys(props);
20+
for (var i = 0; i < keys.length; i++) {
21+
var prop = keys[i];
22+
var text = props[prop].toLowerCase();
23+
if (item[prop].toString().toLowerCase().indexOf(text) !== -1) {
24+
itemMatches = true;
25+
break;
26+
}
27+
}
28+
29+
if (itemMatches) {
30+
out.push(item);
31+
}
32+
});
33+
} else {
34+
// Let the output be the input untouched
35+
out = items;
36+
}
37+
38+
return out;
39+
}
40+
});
41+
542
app.controller('DemoCtrl', function($scope, $http) {
643
$scope.disabled = undefined;
744

@@ -32,13 +69,13 @@ app.controller('DemoCtrl', function($scope, $http) {
3269
];
3370

3471
$scope.address = {};
35-
$scope.getAddress = function(address) {
72+
$scope.refreshAddresses = function(address) {
3673
var params = {address: address, sensor: false};
3774
return $http.get(
3875
'http://maps.googleapis.com/maps/api/geocode/json',
3976
{params: params}
4077
).then(function(response) {
41-
return response.data.results;
78+
$scope.addresses = response.data.results
4279
});
4380
};
4481

examples/select2-bootstrap3.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<!--
88
IE8 support, see AngularJS Internet Explorer Compatibility http://docs.angularjs.org/guide/ie
9-
For Firefox 3.6, you will need to include jQuery
9+
For Firefox 3.6, you will also need to include jQuery and ECMAScript 5 shim
1010
-->
1111
<!--[if lt IE 9]>
1212
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.js"></script>

examples/selectize-bootstrap3.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<!--
88
IE8 support, see AngularJS Internet Explorer Compatibility http://docs.angularjs.org/guide/ie
9-
For Firefox 3.6, you will need to include jQuery
9+
For Firefox 3.6, you will also need to include jQuery and ECMAScript 5 shim
1010
-->
1111
<!--[if lt IE 9]>
1212
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.js"></script>

0 commit comments

Comments
 (0)