File tree Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -68,17 +68,17 @@ var requiredDirective = ['$parse', function($parse) {
68
68
require : '?ngModel' ,
69
69
link : function ( scope , elm , attr , ctrl ) {
70
70
if ( ! ctrl ) return ;
71
- var oldVal = attr . required || $parse ( attr . ngRequired ) ( scope ) ;
71
+ var value = attr . required || $parse ( attr . ngRequired ) ( scope ) ;
72
72
73
73
attr . required = true ; // force truthy in case we are on non input element
74
74
75
75
ctrl . $validators . required = function ( modelValue , viewValue ) {
76
- return ! attr . required || ! ctrl . $isEmpty ( viewValue ) ;
76
+ return ! value || ! ctrl . $isEmpty ( viewValue ) ;
77
77
} ;
78
78
79
- attr . $observe ( 'required' , function ( val ) {
80
- if ( oldVal !== val ) {
81
- oldVal = val ;
79
+ attr . $observe ( 'required' , function ( newVal ) {
80
+ if ( value !== newVal ) {
81
+ value = newVal ;
82
82
ctrl . $validate ( ) ;
83
83
}
84
84
} ) ;
Original file line number Diff line number Diff line change @@ -730,5 +730,19 @@ describe('validators', function() {
730
730
731
731
expect ( helper . validationCounter . required ) . toBe ( 1 ) ;
732
732
} ) ;
733
+
734
+ it ( 'should validate once when inside ngRepeat, and set the "required" error when ngRequired is false by default' , function ( ) {
735
+ $rootScope . isRequired = false ;
736
+ $rootScope . refs = { } ;
737
+
738
+ var elm = helper . compileInput (
739
+ '<div ng-repeat="input in [0]">' +
740
+ '<input type="text" ng-ref="refs.input" ng-ref-read="ngModel" ng-model="value" ng-required="isRequired" validation-spy="required" />' +
741
+ '</div>' ) ;
742
+
743
+ expect ( helper . validationCounter . required ) . toBe ( 1 ) ;
744
+ expect ( $rootScope . refs . input . $error . required ) . toBeUndefined ( ) ;
745
+ } ) ;
746
+
733
747
} ) ;
734
748
} ) ;
You can’t perform that action at this time.
0 commit comments