Skip to content

Commit

Permalink
feat(typeahead): apply angular watch to the typeahead-editable setting
Browse files Browse the repository at this point in the history
  • Loading branch information
damon.friendship committed Nov 10, 2015
1 parent 80df015 commit 33dc3f7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/typeahead/test/typeahead.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,24 @@ describe('typeahead tests', function() {
expect(inputEl.val()).toEqual('bar');
});

it('should support changing the editable property to limit model bindings to matches only', function() {
$scope.isEditable = true;
var element = prepareInputEl('<div><input ng-model="result" uib-typeahead="item for item in source | filter:$viewValue" typeahead-editable="isEditable"></div>');
$scope.isEditable = false;
$scope.$digest();
changeInputValueTo(element, 'not in matches');
expect($scope.result).toEqual(undefined);
});

it('should support changing the editable property to bind view value to model even if not part of matches', function() {
$scope.isEditable = false;
var element = prepareInputEl('<div><input ng-model="result" uib-typeahead="item for item in source | filter:$viewValue" typeahead-editable="isEditable"></div>');
$scope.isEditable = true;
$scope.$digest();
changeInputValueTo(element, 'not in matches');
expect($scope.result).toEqual('not in matches');
});

it('should bind loading indicator expression', inject(function($timeout) {
$scope.isLoading = false;
$scope.loadMatches = function(viewValue) {
Expand Down
3 changes: 3 additions & 0 deletions src/typeahead/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap

//should it restrict model values to the ones selected from the popup only?
var isEditable = originalScope.$eval(attrs.typeaheadEditable) !== false;
originalScope.$watch(attrs.typeaheadEditable, function (newVal) {
isEditable = newVal !== false;
});

//binding to a variable that indicates if matches are being retrieved asynchronously
var isLoadingSetter = $parse(attrs.typeaheadLoading).assign || angular.noop;
Expand Down

0 comments on commit 33dc3f7

Please sign in to comment.