Skip to content
This repository was archived by the owner on Jul 1, 2020. It is now read-only.

Commit 5c83d91

Browse files
committed
Merge pull request #15 from tlastad/master
Get form within scope
2 parents 7fb51b5 + 93bfbc3 commit 5c83d91

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/validation-common.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,24 @@ angular
280280
return isFieldValid;
281281
} // validate()
282282

283-
//----
284-
// Private functions declaration
285-
//----------------------------------
286-
283+
//----
284+
// Private functions declaration
285+
//----------------------------------
286+
287+
/** Get form within scope (if found)
288+
* @param self
289+
*/
290+
function getScopeForm(self) {
291+
var forms = document.querySelectorAll('form');
292+
for (var i = 0; i < forms.length; i++) {
293+
var form = document.querySelectorAll('form')[i];
294+
if (form && form.name && self.scope[form.name]) {
295+
return self.scope[form.name];
296+
}
297+
}
298+
return null;
299+
}
300+
287301
/** Add the error to the validation summary
288302
* @param self
289303
* @param string elmName: element name (name attribute)
@@ -309,9 +323,9 @@ angular
309323

310324
// save validation summary 2 variable locations, inside the scope object and also in the form object (if found)
311325
self.scope.$validationSummary = validationSummary;
312-
var formName = angular.element(document.querySelector('form')).attr('name');
313-
if(!!formName) {
314-
self.scope[formName].$validationSummary = validationSummary;
326+
var form = getScopeForm(self);
327+
if (form) {
328+
form.$validationSummary = validationSummary;
315329
}
316330
}
317331

0 commit comments

Comments
 (0)