This repository was archived by the owner on May 29, 2019. It is now read-only.
File tree 2 files changed +20
-3
lines changed
2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -271,6 +271,18 @@ describe('typeahead tests', function () {
271
271
var matchHighlight = findMatches ( element ) . find ( 'a' ) . html ( ) ;
272
272
expect ( matchHighlight ) . toEqual ( 'prefix<strong>fo</strong>o' ) ;
273
273
} ) ;
274
+
275
+ it ( 'should by default bind view value to model even if not part of matches' , function ( ) {
276
+ var element = prepareInputEl ( "<div><input ng-model='result' typeahead='item for item in source | filter:$viewValue'></div>" ) ;
277
+ changeInputValueTo ( element , 'not in matches' ) ;
278
+ expect ( $scope . result ) . toEqual ( 'not in matches' ) ;
279
+ } ) ;
280
+
281
+ it ( 'should support the editable property to limit model bindings to matches only' , function ( ) {
282
+ var element = prepareInputEl ( "<div><input ng-model='result' typeahead='item for item in source | filter:$viewValue' typeahead-editable='false'></div>" ) ;
283
+ changeInputValueTo ( element , 'not in matches' ) ;
284
+ expect ( $scope . result ) . toEqual ( undefined ) ;
285
+ } ) ;
274
286
} ) ;
275
287
276
288
describe ( 'selecting a match' , function ( ) {
Original file line number Diff line number Diff line change @@ -46,6 +46,9 @@ angular.module('ui.bootstrap.typeahead', [])
46
46
//expressions used by typeahead
47
47
var parserResult = typeaheadParser . parse ( attrs . typeahead ) ;
48
48
49
+ //should it restrict model values to the ones selected from the popup only?
50
+ var isEditable = originalScope . $eval ( attrs . typeaheadEditable ) !== false ;
51
+
49
52
//create a child scope for the typeahead directive so we are not polluting original scope
50
53
//with typeahead-specific data (matches, query etc.)
51
54
var scope = originalScope . $new ( ) ;
@@ -107,7 +110,7 @@ angular.module('ui.bootstrap.typeahead', [])
107
110
}
108
111
}
109
112
110
- return undefined ;
113
+ return isEditable ? inputValue : undefined ;
111
114
} ) ;
112
115
113
116
modelCtrl . $render = function ( ) {
@@ -151,13 +154,15 @@ angular.module('ui.bootstrap.typeahead', [])
151
154
152
155
} else if ( evt . which === 27 ) {
153
156
evt . stopPropagation ( ) ;
154
- scope . matches = [ ] ;
157
+
158
+ resetMatches ( ) ;
155
159
scope . $digest ( ) ;
156
160
}
157
161
} ) ;
158
162
159
163
$document . find ( 'body' ) . bind ( 'click' , function ( ) {
160
- scope . matches = [ ] ;
164
+
165
+ resetMatches ( ) ;
161
166
scope . $digest ( ) ;
162
167
} ) ;
163
168
You can’t perform that action at this time.
0 commit comments