diff --git a/src/typeahead/docs/readme.md b/src/typeahead/docs/readme.md index a2ac10c9ae..b5f1d7777f 100644 --- a/src/typeahead/docs/readme.md +++ b/src/typeahead/docs/readme.md @@ -27,7 +27,7 @@ The typeahead directives provide several attributes: * `typeahead-append-to` _(Defaults: null)_ : Should the typeahead popup be appended to an element instead of the parent element? -* `typeahead-editable` +* `typeahead-editable` _(Defaults: true)_ : Should it restrict model values to the ones selected from the popup only ? diff --git a/src/typeahead/test/typeahead.spec.js b/src/typeahead/test/typeahead.spec.js index be2fd36f7c..5e122cd953 100644 --- a/src/typeahead/test/typeahead.spec.js +++ b/src/typeahead/test/typeahead.spec.js @@ -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('
'); + $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('
'); + $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) { diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js index 3c65ebc56b..1f7aff6ece 100644 --- a/src/typeahead/typeahead.js +++ b/src/typeahead/typeahead.js @@ -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;