diff --git a/src/validation-common.js b/src/validation-common.js index e03a65b..74422cb 100644 --- a/src/validation-common.js +++ b/src/validation-common.js @@ -280,10 +280,24 @@ angular return isFieldValid; } // validate() - //---- - // Private functions declaration - //---------------------------------- - + //---- + // Private functions declaration + //---------------------------------- + + /** Get form within scope (if found) + * @param self + */ + function getScopeForm(self) { + var forms = document.querySelectorAll('form'); + for (var i = 0; i < forms.length; i++) { + var form = document.querySelectorAll('form')[i]; + if (form && form.name && self.scope[form.name]) { + return self.scope[form.name]; + } + } + return null; + } + /** Add the error to the validation summary * @param self * @param string elmName: element name (name attribute) @@ -309,9 +323,9 @@ angular // save validation summary 2 variable locations, inside the scope object and also in the form object (if found) self.scope.$validationSummary = validationSummary; - var formName = angular.element(document.querySelector('form')).attr('name'); - if(!!formName) { - self.scope[formName].$validationSummary = validationSummary; + var form = getScopeForm(self); + if (form) { + form.$validationSummary = validationSummary; } }