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

feat(typeahead): apply angular watch to the typeahead-editable setting #4820

Closed
wants to merge 2 commits into from
Closed
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
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