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

Commit

Permalink
Fix a small issue introduced by last commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Dec 16, 2016
1 parent df85bb0 commit da1f426
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 24 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-validation-ghiscoding",
"version": "1.5.11",
"version": "1.5.12",
"author": "Ghislain B.",
"description": "Angular-Validation Directive and Service (ghiscoding)",
"main": [
Expand Down
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Angular-Validation change logs

1.5.12 (2016-12-15) Fix a small issue introduced by last commit (Angular Form overwritten with simple object).
1.5.11 (2016-12-15) Fix checkFormValidity with formName argument, issues #135 #139 #140 #141
1.5.10 (2016-12-13) Fix UI Router issue by adding a UI Router watch on $stateChangeStart, issue #137
1.5.9 (2016-10-14) Updated main entry at package.json to work with WebPack, issue #128
Expand Down
6 changes: 3 additions & 3 deletions dist/angular-validation.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "angular-validation-ghiscoding",
"version": "1.5.11",
"version": "1.5.12",
"author": "Ghislain B.",
"description": "Angular-Validation Directive and Service (ghiscoding)",
"main": "dist/angular-validation.min",
"dependencies": {},
"devDependencies": {
"del": "^1.2.1",
"fs": "0.0.1-security",
"fs": "0.0.0",
"gulp": "^3.9.0",
"gulp-angular-protractor": "^0.2.0",
"gulp-bump": "^0.3.1",
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Angular Validation (Directive / Service)
`Version: 1.5.11`
`Version: 1.5.12`
### Forms Validation with Angular made easy!
##### (Concept comes from the amazing Laravel)

Expand Down
52 changes: 35 additions & 17 deletions src/validation-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,30 @@ angular
return -1;
}

/** From a javascript plain form object, find its equivalent Angular object
* @param object formObj
* @param object self
* @return object angularParentForm or null
*/
function findAngularParentFormInScope(formObj, self) {
var formName = (!!formObj) ? formObj.getAttribute("name") : null;

if (!!formObj && !!formName) {
parentForm = (!!_globalOptions && !!_globalOptions.controllerAs && formName.indexOf('.') >= 0)
? objectFindById(self.scope, formName, '.')
: self.scope[formName];

if(!!parentForm) {
if (typeof parentForm.$name === "undefined") {
parentForm.$name = formName; // make sure it has a $name, since we use that variable later on
}
return parentForm;
}
}

return null;
}

/** Get the element's parent Angular form (if found)
* @param string: element input name
* @param object self
Expand All @@ -811,28 +835,22 @@ angular

for (var i = 0; i < forms.length; i++) {
var form = forms[i].form;
var formName = (!!form) ? form.getAttribute("name") : null;

if (!!form && !!formName) {
parentForm = (!!_globalOptions && !!_globalOptions.controllerAs && formName.indexOf('.') >= 0)
? objectFindById(self.scope, formName, '.')
: self.scope[formName];

if(!!parentForm) {
if (typeof parentForm.$name === "undefined") {
parentForm.$name = formName; // make sure it has a $name, since we use that variable later on
}
return parentForm;
}
var angularParentForm = findAngularParentFormInScope(form, self);
if(!!angularParentForm) {
return angularParentForm;
}
}

// if we haven't found a form yet, then we have a special angular element, let's try with .closest (this might not work with older browser)
// if we haven't found a form yet, then we have a special angular element, let's try with .closest
if(!form) {
var element = document.querySelector('[name="'+elmName+'"]');
if(element) {
form = element.closest("form");
var element = document.querySelector('[name="'+elmName+'"]');
if(!!element) {
var form = element.closest("form");
var angularParentForm = findAngularParentFormInScope(form, self);
if(!!angularParentForm) {
return angularParentForm;
}
}
}

// falling here with a form name but without a form object found in the scope is often due to isolate scope
Expand Down

0 comments on commit da1f426

Please sign in to comment.