Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
fix(typeahead): fix label rendering for equal model and items names
Browse files Browse the repository at this point in the history
  • Loading branch information
pkozlowski-opensource committed Aug 10, 2013
1 parent 64df05e commit 5de7121
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/typeahead/test/typeahead.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,14 @@ describe('typeahead tests', function () {
var inputEl = findInput(prepareInputEl("<div><input ng-model='result' typeahead='state as state.name + \" \" + state.code for state in states | filter:$viewValue'></div>"));
expect(inputEl.val()).toEqual('');
});

it('issue 786 - name of internal model should not conflict with scope model name', function () {
$scope.state = $scope.states[0];
var element = prepareInputEl("<div><input ng-model='state' typeahead='state as state.name for state in states | filter:$viewValue'></div>");
var inputEl = findInput(element);

expect(inputEl.val()).toEqual('Alaska');
});
});

describe('input formatting', function () {
Expand Down
5 changes: 3 additions & 2 deletions src/typeahead/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,13 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position'])
return inputFormatter(originalScope, locals);

} else {
locals[parserResult.itemName] = modelValue;

//it might happen that we don't have enough info to properly render input value
//we need to check for this situation and simply return model value if we can't apply custom formatting
locals[parserResult.itemName] = modelValue;
candidateViewValue = parserResult.viewMapper(originalScope, locals);
emptyViewValue = parserResult.viewMapper(originalScope, {});
locals[parserResult.itemName] = undefined;
emptyViewValue = parserResult.viewMapper(originalScope, locals);

return candidateViewValue!== emptyViewValue ? candidateViewValue : modelValue;
}
Expand Down

0 comments on commit 5de7121

Please sign in to comment.