@@ -29,7 +29,8 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position'])
2929 } ;
3030} ] )
3131
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 ) {
3334
3435 var HOT_KEYS = [ 9 , 13 , 27 , 38 , 40 ] ;
3536
@@ -158,7 +159,12 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position'])
158159 }
159160 }
160161
161- return isEditable ? inputValue : undefined ;
162+ if ( isEditable ) {
163+ return inputValue ;
164+ } else {
165+ modelCtrl . $setValidity ( 'editable' , false ) ;
166+ return undefined ;
167+ }
162168 } ) ;
163169
164170 modelCtrl . $formatters . push ( function ( modelValue ) {
@@ -192,15 +198,17 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position'])
192198 locals [ parserResult . itemName ] = item = scope . matches [ activeIdx ] . model ;
193199 model = parserResult . modelMapper ( originalScope , locals ) ;
194200 $setModelValue ( originalScope , model ) ;
201+ modelCtrl . $setValidity ( 'editable' , true ) ;
195202
196203 onSelectCallback ( originalScope , {
197204 $item : item ,
198205 $model : model ,
199206 $label : parserResult . viewMapper ( originalScope , locals )
200207 } ) ;
201208
202- //return focus to the input element if a mach was selected via a mouse click event
203209 resetMatches ( ) ;
210+
211+ //return focus to the input element if a mach was selected via a mouse click event
204212 element [ 0 ] . focus ( ) ;
205213 } ;
206214
0 commit comments