@@ -313,6 +313,39 @@ describe('typeahead tests', function() {
313
313
expect ( $scope . form . input . $error . parse ) . toBeFalsy ( ) ;
314
314
} ) ;
315
315
316
+ // fix for #6032
317
+ it ( 'should clear errors and refresh scope after blur for typeahead-editable="false"' , function ( ) {
318
+ var element = prepareInputEl (
319
+ '<div><form name="form" ng-class="{invalid : form.input.$invalid}">' +
320
+ '<input name="input" ng-model="result" uib-typeahead="item for item in source | filter:$viewValue" typeahead-editable="false">' +
321
+ '</form></div>' ) ;
322
+ var inputEl = findInput ( element ) ;
323
+
324
+ // first try
325
+ changeInputValueTo ( element , 'not in matches' ) ;
326
+ expect ( $scope . result ) . toEqual ( undefined ) ;
327
+ expect ( inputEl . val ( ) ) . toEqual ( 'not in matches' ) ;
328
+ expect ( element . find ( 'form' ) ) . toHaveClass ( 'invalid' ) ;
329
+ inputEl . blur ( ) ;
330
+
331
+ expect ( inputEl . val ( ) ) . toEqual ( '' ) ; // <-- input is reset
332
+ expect ( $scope . form . input . $error . editable ) . toBeFalsy ( ) ;
333
+ expect ( $scope . form . input . $error . parse ) . toBeFalsy ( ) ;
334
+ expect ( element . find ( 'form' ) ) . not . toHaveClass ( 'invalid' ) ; // <-- form has no error (it always works for some reason)
335
+
336
+ // second try
337
+ changeInputValueTo ( element , 'not in matches' ) ;
338
+ expect ( $scope . result ) . toEqual ( undefined ) ;
339
+ expect ( inputEl . val ( ) ) . toEqual ( 'not in matches' ) ;
340
+ expect ( element . find ( 'form' ) ) . toHaveClass ( 'invalid' ) ;
341
+ inputEl . blur ( ) ;
342
+
343
+ expect ( inputEl . val ( ) ) . toEqual ( '' ) ; // <-- input is reset
344
+ expect ( $scope . form . input . $error . editable ) . toBeFalsy ( ) ;
345
+ expect ( $scope . form . input . $error . parse ) . toBeFalsy ( ) ;
346
+ expect ( element . find ( 'form' ) ) . not . toHaveClass ( 'invalid' ) ; // <-- form has no error (it didn't work prior to #6032 fix)
347
+ } ) ;
348
+
316
349
it ( 'should go through other validators after blur for typeahead-editable="false"' , function ( ) {
317
350
var element = prepareInputEl (
318
351
'<div><form name="form">' +
0 commit comments