@@ -29,7 +29,8 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position'])
29
29
} ;
30
30
} ] )
31
31
32
- . directive ( 'typeahead' , [ '$compile' , '$parse' , '$q' , '$timeout' , '$document' , '$position' , 'typeaheadParser' , function ( $compile , $parse , $q , $timeout , $document , $position , typeaheadParser ) {
32
+ . directive ( 'typeahead' , [ '$compile' , '$parse' , '$q' , '$timeout' , '$document' , '$position' , 'typeaheadParser' ,
33
+ function ( $compile , $parse , $q , $timeout , $document , $position , typeaheadParser ) {
33
34
34
35
var HOT_KEYS = [ 9 , 13 , 27 , 38 , 40 ] ;
35
36
@@ -158,7 +159,12 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position'])
158
159
}
159
160
}
160
161
161
- return isEditable ? inputValue : undefined ;
162
+ if ( isEditable ) {
163
+ return inputValue ;
164
+ } else {
165
+ modelCtrl . $setValidity ( 'editable' , false ) ;
166
+ return undefined ;
167
+ }
162
168
} ) ;
163
169
164
170
modelCtrl . $formatters . push ( function ( modelValue ) {
@@ -192,15 +198,17 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position'])
192
198
locals [ parserResult . itemName ] = item = scope . matches [ activeIdx ] . model ;
193
199
model = parserResult . modelMapper ( originalScope , locals ) ;
194
200
$setModelValue ( originalScope , model ) ;
201
+ modelCtrl . $setValidity ( 'editable' , true ) ;
195
202
196
203
onSelectCallback ( originalScope , {
197
204
$item : item ,
198
205
$model : model ,
199
206
$label : parserResult . viewMapper ( originalScope , locals )
200
207
} ) ;
201
208
202
- //return focus to the input element if a mach was selected via a mouse click event
203
209
resetMatches ( ) ;
210
+
211
+ //return focus to the input element if a mach was selected via a mouse click event
204
212
element [ 0 ] . focus ( ) ;
205
213
} ;
206
214
0 commit comments