Skip to content

Commit

Permalink
Merge pull request angular-ui#256 from JeffGreat/master
Browse files Browse the repository at this point in the history
Add possibility to find value according to a property of the model
  • Loading branch information
amcdnl committed Jan 22, 2015
2 parents 1af3a56 + b8bcd8a commit 28466ab
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,13 @@
for (var p = list.length - 1; p >= 0; p--) {
locals[$select.parserResult.itemName] = list[p];
result = $select.parserResult.modelMapper(scope, locals);
if($select.parserResult.trackByExp){
var matches = /\.(.+)/.exec($select.parserResult.trackByExp);
if(matches.length>0 && result[matches[1]] == value[matches[1]]){
resultMultiple.unshift(list[p]);
return true;
}
}
if (result == value){
resultMultiple.unshift(list[p]);
return true;
Expand Down
15 changes: 15 additions & 0 deletions test/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,21 @@ describe('ui-select tests', function() {

expect(getMatchLabel(el)).toEqual('Adam');
});

it('should correctly render initial state with track by feature', function() {
var el = compileTemplate(
'<ui-select ng-model="selection.selected"> \
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
<ui-select-choices repeat="person in people | filter: $select.search track by person.name"> \
<div ng-bind-html="person.name | highlight: $select.search"></div> \
<div ng-bind-html="person.email | highlight: $select.search"></div> \
</ui-select-choices> \
</ui-select>'
);
scope.selection.selected = { name: 'Samantha', email: 'something different than array source', group: 'bar', age: 30 };
scope.$digest();
expect(getMatchLabel(el)).toEqual('Samantha');
});

it('should display the choices when activated', function() {
var el = createUiSelect();
Expand Down

0 comments on commit 28466ab

Please sign in to comment.