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

Add possibility to find value according to a property of the model #256

Merged
merged 3 commits into from
Jan 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,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 @@ -157,6 +157,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