From b4ae83c7970f0b12ac936f4e0d390135ee2bdcf6 Mon Sep 17 00:00:00 2001 From: "Nassos A. Michas" Date: Wed, 3 May 2017 13:20:43 +0300 Subject: [PATCH] Support for deep references --- bower.json | 2 +- src/QFormJSRValidationModule.js | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/bower.json b/bower.json index 02f5574..c18cd89 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "qlack2-bower-angular-jsr-validation", - "version": "1.0.0", + "version": "1.0.1", "authors": [ "European Dynamics SA" ], diff --git a/src/QFormJSRValidationModule.js b/src/QFormJSRValidationModule.js index 3176c42..347f730 100644 --- a/src/QFormJSRValidationModule.js +++ b/src/QFormJSRValidationModule.js @@ -45,10 +45,10 @@ angular.module('QFormJSRValidation', []) // When the target form element becomes invalid, show validation errors. var validWatch = scope.$watch(formName + "[\'" + attrs.formElementName + "\'].$valid", function(newVal, oldVal) { - if (newVal != undefined) { + if (newVal != undefined && newVal == false) { // Iterate through all errors. var errorHtml = ""; @@ -92,7 +92,7 @@ angular.module('QFormJSRValidation', []) }, true); // Create watchers for the validity and pristine of each tracked - // fields. When any of the tracked fields is changed, the generic + // field. When any of the tracked fields is changed, the generic // form error is removed. var trackFields = attrs.trackFields.split(","); var pristineWatch = []; @@ -120,7 +120,7 @@ angular.module('QFormJSRValidation', []) require: 'form', link: function (scope, element) { element.on('submit', function () { - var form = scope[element.context.name]; + var form = deep_value(scope, element.context.name); // Reset field errors. $.each(form, function(key) { if (typeof form[key] == "object") { @@ -141,6 +141,14 @@ angular.module('QFormJSRValidation', []) }; }]); +/** Find an object possible deeply nested */ +var deep_value = function(obj, path){ + for (var i=0, path=path.split('.'), len=path.length; i