Skip to content

Commit 2a9fc76

Browse files
committed
Merge pull request angular-ui#1216 from angular-ui/fix-patch-0.13.0
Fix for v0.13.0
2 parents b1415f4 + e38baf4 commit 2a9fc76

File tree

4 files changed

+60
-8
lines changed

4 files changed

+60
-8
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
## [v0.13.1][v0.13.1] (2015-09-29)
5+
### Fixed
6+
- Modify regex to accept a full 'collection expression' when not using (key,value) syntax [#1216](https://github.com/angular-ui/ui-select/pull/1216)
7+
- Avoid to recalculate position when set 'down' [#1214](https://github.com/angular-ui/ui-select/issues/1214#issuecomment-144271352)
8+
49
## [v0.13.0][v0.13.0] (2015-09-29)
510
### Added
611
- Allow to configure default dropdown position [#1213](https://github.com/angular-ui/ui-select/pull/1213)
@@ -18,5 +23,5 @@ All notable changes to this project will be documented in this file.
1823
- Fix to work correctly with debugInfoEnabled(false) [#1131](https://github.com/angular-ui/ui-select/pull/1131)
1924
- Limit the maximum number of selections allowed in multiple mode [#1110](https://github.com/angular-ui/ui-select/pull/1110)
2025

21-
[unreleased]: https://github.com/angular-ui/ui-select/compare/v0.13.0...HEAD
26+
[v0.13.1]: https://github.com/angular-ui/ui-select/compare/v0.13.0...v0.13.1
2227
[v0.13.0]: https://github.com/angular-ui/ui-select/compare/v0.12.1...v0.13.0

src/uiSelectController.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ uis.controller('uiSelectCtrl',
169169
}
170170

171171
ctrl.refreshItems = function (data){
172-
$scope.calculateDropdownPos();
173172
data = data || ctrl.parserResult.source($scope);
174173
var selectedItems = ctrl.selected;
175174
//TODO should implement for single mode removeSelected
@@ -181,6 +180,9 @@ uis.controller('uiSelectCtrl',
181180
ctrl.setItemsFn(filteredItems);
182181
}
183182
}
183+
if (ctrl.dropdownPosition === 'auto' || ctrl.dropdownPosition === 'up'){
184+
$scope.calculateDropdownPos();
185+
}
184186
};
185187

186188
// See https://github.com/angular/angular.js/blob/v1.2.15/src/ng/directive/ngRepeat.js#L259

src/uisRepeatParserService.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,39 @@ uis.service('uisRepeatParser', ['uiSelectMinErr','$parse', function(uiSelectMinE
2121
self.parse = function(expression) {
2222

2323

24-
//0000000000000000000000000000000000011111111100000000000000022222222222222003333333333333333333333000044444444444444444400000000000000005555500000666666666666600000000000000000000007777777770000000
25-
var match = expression.match(/^\s*(?:([\s\S]+?)\s+as\s+)?(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+([\w]+)\s*(|\s*[\s\S]+?)?(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);
24+
var match;
25+
var isObjectCollection = /\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)/.test(expression);
26+
// If an array is used as collection
27+
28+
// if (isObjectCollection){
29+
//00000000000000000000000000000111111111000000000000000222222222222220033333333333333333333330000444444444444444444000000000000000556666660000077777777777755000000000000000000000088888880000000
30+
match = expression.match(/^\s*(?:([\s\S]+?)\s+as\s+)?(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+(([\w]+)?\s*(|\s*[\s\S]+?))?(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);
31+
32+
// 1 Alias
33+
// 2 Item
34+
// 3 Key on (key,value)
35+
// 4 Value on (key,value)
36+
// 5 Collection expresion (only used when using an array collection)
37+
// 6 Object that will be converted to Array when using (key,value) syntax
38+
// 7 Filters that will be applied to #6 when using (key,value) syntax
39+
// 8 Track by
2640

2741
if (!match) {
2842
throw uiSelectMinErr('iexp', "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",
2943
expression);
3044
}
45+
if (!match[6] && isObjectCollection) {
46+
throw uiSelectMinErr('iexp', "Expected expression in form of '_item_ as (_key_, _item_) in _ObjCollection_ [ track by _id_]' but got '{0}'.",
47+
expression);
48+
}
3149

3250
return {
3351
itemName: match[4] || match[2], // (lhs) Left-hand side,
3452
keyName: match[3], //for (key, value) syntax
35-
source: $parse(!match[3] ? match[5] + (match[6] || ''): match[5]), //concat source with filters if its an array
36-
sourceName: match[5],
37-
filters: match[6],
38-
trackByExp: match[7],
53+
source: $parse(!match[3] ? match[5] : match[6]),
54+
sourceName: match[6],
55+
filters: match[7],
56+
trackByExp: match[8],
3957
modelMapper: $parse(match[1] || match[4] || match[2]),
4058
repeatExpression: function (grouped) {
4159
var expression = this.itemName + ' in ' + (grouped ? '$group.items' : '$select.items');

test/select.spec.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,33 @@ describe('ui-select tests', function() {
285285

286286
});
287287

288+
it('should should accept a "collection expresion" only if its not (key, value) repeat syntax', function() {
289+
290+
var locals = {};
291+
locals.people = { 'WC' : {name: 'Wladimir'}, 'SH' : {name: 'Samantha'}};
292+
locals.person = locals.people['WC'];
293+
294+
var parserResult = uisRepeatParser.parse('person.name as person in (peopleNothing || people)');
295+
expect(parserResult.itemName).toBe('person');
296+
expect(parserResult.modelMapper(locals)).toBe(locals.person.name);
297+
// expect(parserResult.source(locals)).toBe(locals.people);
298+
299+
});
300+
301+
it('should should throw if "collection expresion" used and (key, value) repeat syntax', function() {
302+
303+
var locals = {};
304+
locals.people = { 'WC' : {name: 'Wladimir'}, 'SH' : {name: 'Samantha'}};
305+
locals.person = locals.people['WC'];
306+
307+
function errorFunctionWrapper(){
308+
uisRepeatParser.parse('person.name as (key,person) in (people | someFilter)');
309+
}
310+
311+
expect(errorFunctionWrapper).toThrow();
312+
313+
});
314+
288315
it('should compile child directives', function() {
289316
var el = createUiSelect();
290317

0 commit comments

Comments
 (0)