@@ -74,20 +74,19 @@ angular.module('angularValidator').directive('angularValidator', ['$injector', '
7474                    // If the form is valid then call the function that is declared in the angular-validator-submit attribute on the form element 
7575                    if  ( scopeForm . $valid )  { 
7676                        scope . $apply ( function ( )  { 
77-                             scope . $eval ( DOMForm . attributes [ " angular-validator-submit" ] . value ) ; 
77+                             scope . $eval ( attrs [ ' angular-validator-submit' ] ) ; 
7878                        } ) ; 
7979                    } 
8080                } ) ; 
8181
82- 
82+                  // Clear all the form values. Set everything to pristine. 
8383                scopeForm . reset  =  function ( )  { 
84-                     // Clear all the form values 
85-                     for  ( var  i  =  0 ;  i  <  DOMForm . length ;  i ++ )  { 
86-                         if  ( DOMForm [ i ] . name )  { 
87-                             scopeForm [ DOMForm [ i ] . name ] . $setViewValue ( "" ) ; 
88-                             scopeForm [ DOMForm [ i ] . name ] . $render ( ) ; 
84+                     angular . forEach ( DOMForm ,  function ( formElement )  { 
85+                         if  ( formElement . name )  { 
86+                             scopeForm [ formElement . name ] . $setViewValue ( "" ) ; 
87+                             scopeForm [ formElement . name ] . $render ( ) ; 
8988                        } 
90-                     } 
89+                     } ) ; 
9190                    scopeForm . submitted  =  false ; 
9291                    scopeForm . $setPristine ( ) ; 
9392                } ; 
@@ -96,7 +95,8 @@ angular.module('angularValidator').directive('angularValidator', ['$injector', '
9695                // Setup watches on all form fields  
9796                setupWatches ( DOMForm ) ; 
9897
99-                 //check if there is invalid message service for the entire form; if yes, return the injected service; if no, return false; 
98+                 // Check if there is invalid message service for the entire form;  
99+                 // if yes, return the injected service; if no, return false; 
100100                function  hasFormInvalidMessage ( formElement )  { 
101101                    if  ( formElement  &&  'invalid-message'  in  formElement . attributes )  { 
102102                        return  $injector . get ( formElement . attributes [ 'invalid-message' ] . value ) ; 
@@ -117,7 +117,7 @@ angular.module('angularValidator').directive('angularValidator', ['$injector', '
117117                } 
118118
119119
120-                 // Setup $watch on a single formfield  
120+                 // Setup $watch on a single form element  
121121                function  setupWatch ( elementToWatch ,  formInvalidMessage )  { 
122122                    // If element is set to validate on blur then update the element on blur 
123123                    if  ( "validate-on"  in  elementToWatch . attributes  &&  elementToWatch . attributes [ "validate-on" ] . value  ===  "blur" )  { 
@@ -131,7 +131,6 @@ angular.module('angularValidator').directive('angularValidator', ['$injector', '
131131                            return  elementToWatch . value  +  elementToWatch . required  +  scopeForm . submitted  +  checkElementValidity ( elementToWatch )  +  getDirtyValue ( scopeForm [ elementToWatch . name ] )  +  getValidValue ( scopeForm [ elementToWatch . name ] ) ; 
132132                        } , 
133133                        function ( )  { 
134- 
135134                            if  ( scopeForm . submitted )  { 
136135                                updateValidationMessage ( elementToWatch ,  formInvalidMessage ) ; 
137136                                updateValidationClass ( elementToWatch ) ; 
@@ -158,19 +157,15 @@ angular.module('angularValidator').directive('angularValidator', ['$injector', '
158157
159158                // Returns the $dirty value of the element if it exists 
160159                function  getDirtyValue ( element )  { 
161-                     if  ( element )  { 
162-                         if  ( "$dirty"  in  element )  { 
163-                             return  element . $dirty ; 
164-                         } 
160+                     if  ( element  &&  "$dirty"  in  element )  { 
161+                         return  element . $dirty ; 
165162                    } 
166163                } 
167- 
168- 
164+                  
165+                  // Returns the $valid value of the element if it exists 
169166                function  getValidValue ( element )  { 
170-                     if  ( element )  { 
171-                         if  ( "$valid"  in  element )  { 
172-                             return  element . $valid ; 
173-                         } 
167+                     if  ( element  &&  "$valid"  in  element )  { 
168+                         return  element . $valid ; 
174169                    } 
175170                } 
176171
@@ -277,7 +272,7 @@ angular.module('angularValidator').directive('angularValidator', ['$injector', '
277272
278273
279274                    // Only add/remove validation classes if the field is $dirty or the form has been submitted 
280-                     if  ( formField . $dirty  ||  ( scope [ element . form . name ]   &&   scope [ element . form . name ] . submitted ) )  { 
275+                     if  ( formField . $dirty  ||  ( scopeForm . submitted ) )  { 
281276                        if  ( formField . $invalid )  { 
282277                            angular . element ( element . parentNode ) . addClass ( 'has-error' ) ; 
283278
0 commit comments