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) {
6868 require : '?ngModel' ,
6969 link : function ( scope , elm , attr , ctrl ) {
7070 if ( ! ctrl ) return ;
71- var oldVal = attr . required || $parse ( attr . ngRequired ) ( scope ) ;
71+ var value = attr . required || $parse ( attr . ngRequired ) ( scope ) ;
7272
7373 attr . required = true ; // force truthy in case we are on non input element
7474
7575 ctrl . $validators . required = function ( modelValue , viewValue ) {
76- return ! attr . required || ! ctrl . $isEmpty ( viewValue ) ;
76+ return ! value || ! ctrl . $isEmpty ( viewValue ) ;
7777 } ;
7878
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 ;
8282 ctrl . $validate ( ) ;
8383 }
8484 } ) ;
Original file line number Diff line number Diff line change @@ -730,5 +730,19 @@ describe('validators', function() {
730730
731731 expect ( helper . validationCounter . required ) . toBe ( 1 ) ;
732732 } ) ;
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+
733747 } ) ;
734748} ) ;
You can’t perform that action at this time.
0 commit comments