File tree 2 files changed +19
-0
lines changed
2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -2182,6 +2182,8 @@ var ngModelDirective = function() {
2182
2182
}
2183
2183
2184
2184
element . on ( 'blur' , function ( ev ) {
2185
+ if ( modelCtrl . $touched ) return ;
2186
+
2185
2187
scope . $apply ( function ( ) {
2186
2188
modelCtrl . $setTouched ( ) ;
2187
2189
} ) ;
Original file line number Diff line number Diff line change @@ -472,6 +472,23 @@ describe('ngModel', function() {
472
472
dealoc ( element ) ;
473
473
} ) ) ;
474
474
475
+ it ( 'should not cause a digest on "blur" event if control is already touched' ,
476
+ inject ( function ( $compile , $rootScope ) {
477
+
478
+ var element = $compile ( '<form name="myForm">' +
479
+ '<input name="myControl" ng-model="value" >' +
480
+ '</form>' ) ( $rootScope ) ;
481
+ var inputElm = element . find ( 'input' ) ;
482
+ var control = $rootScope . myForm . myControl ;
483
+
484
+ control . $setTouched ( ) ;
485
+ spyOn ( $rootScope , '$apply' ) ;
486
+ browserTrigger ( inputElm , 'blur' ) ;
487
+
488
+ expect ( $rootScope . $apply ) . not . toHaveBeenCalled ( ) ;
489
+
490
+ dealoc ( element ) ;
491
+ } ) ) ;
475
492
476
493
it ( 'should register/deregister a nested ngModel with parent form when entering or leaving DOM' ,
477
494
inject ( function ( $compile , $rootScope ) {
You can’t perform that action at this time.
0 commit comments