@@ -27,6 +27,7 @@ angular
2727 validationService . prototype . addValidator = addValidator ;
2828 validationService . prototype . checkFormValidity = checkFormValidity ;
2929 validationService . prototype . removeValidator = removeValidator ;
30+ validationService . prototype . clearValidationSummary = clearValidationSummary ;
3031 validationService . prototype . setGlobalOptions = setGlobalOptions ;
3132
3233 return validationService ;
@@ -73,7 +74,7 @@ angular
7374 attrs = mergeObjects ( self . validationAttrs , attrs ) ;
7475
7576 // watch the element for any value change, validate it once that happen
76- attrs . scope . $watch ( attrs . elmName , function ( newVal , oldVal ) {
77+ attrs . scope . $watch ( attrs . elmName , function ( newVal , oldVal ) {
7778 if ( newVal === undefined && oldVal !== undefined ) {
7879 self . commonObj . updateErrorMsg ( "INVALID_KEY_CHAR" , { valid : false , translate : true } ) ;
7980 return ;
@@ -84,11 +85,17 @@ angular
8485
8586 self . commonObj . initialize ( attrs . scope , attrs . elm , attrs , attrs . ctrl ) ;
8687 attemptToValidate ( self , newVal ) ;
87- } , true ) ; // $watch()
88+ } , true ) ; // $watch()
8889
8990 return self ;
90- } // addValidator()
91+ } // addValidator()
9192
93+ function clearValidationSummary ( obj ) {
94+ if ( typeof obj === "undefined" || typeof obj . $validationSummary === "undefined" ) {
95+ throw 'checkFormValidity() requires a valid Angular Form or $scope object passed as argument to function properly (ex.: $scope.form1 OR $scope).' ;
96+ }
97+ obj . $validationSummary = [ ] ;
98+ }
9299 /** Is the Form all valid? Loop through Validation Summary to get the answer, if any errors are there then display them and return false
93100 * @param object Angular Form or Scope Object
94101 * @return bool isFormValid
@@ -103,13 +110,12 @@ angular
103110 // loop through $validationSummary and display errors when found on each field
104111 for ( var i = 0 , ln = obj . $validationSummary . length ; i < ln ; i ++ ) {
105112 isValid = false ;
106- elmName = obj . $validationSummary [ i ] . field ;
107- elm = angular . element ( document . querySelector ( '[name="' + elmName + '"]:not([disabled]):not([ng-disabled]' ) ) ;
108- ctrl = angular . element ( elm ) . controller ( 'ngModel' ) ;
113+ elm = obj . $validationSummary [ i ] . obj . elm ;
114+ ctrl = obj . $validationSummary [ i ] . obj . ctrl ;
109115
110116 if ( ! ! elm && elm . length > 0 ) {
111117 ctrl . $setTouched ( ) ; // make the element as it was touched for CSS
112- self . commonObj . updateErrorMsg ( obj . $validationSummary [ i ] . message , { valid : false , elm : elm , submitted : true } ) ;
118+ self . commonObj . updateErrorMsg ( obj . $validationSummary [ i ] . message , { valid : false , obj : obj . $validationSummary [ i ] . obj , submitted : true } ) ;
113119 }
114120 }
115121 return isValid ;
0 commit comments