From 4b17cbff32b1b18aa29bbc8f366fc49a676b9040 Mon Sep 17 00:00:00 2001 From: Tom Sowerby Date: Wed, 4 Nov 2015 10:54:29 +0000 Subject: [PATCH] Allow broadcasting of the formName to validate Allows passing the form name during broadcast to limit validation e.g. $scope.$broadcast('schemaFormValidate', form.$name); This allows nested or multiple forms within the same scope. --- src/directives/schema-validate.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/directives/schema-validate.js b/src/directives/schema-validate.js index 3b96351bd..a606c50c8 100644 --- a/src/directives/schema-validate.js +++ b/src/directives/schema-validate.js @@ -106,7 +106,13 @@ angular.module('schemaForm').directive('schemaValidate', ['sfValidator', '$parse var schema = form.schema; // A bit ugly but useful. - scope.validateField = function() { + scope.validateField = function(formName) { + + // If we have specified a form name, and this model is not within + // that form, then leave things be. + if(formName != undefined && ngModel.$$parentForm.$name !== formName) { + return; + } // Special case: arrays // TODO: Can this be generalized in a way that works consistently? @@ -153,7 +159,9 @@ angular.module('schemaForm').directive('schemaValidate', ['sfValidator', '$parse }); // Listen to an event so we can validate the input on request - scope.$on('schemaFormValidate', scope.validateField); + scope.$on('schemaFormValidate', function(event, formName) { + scope.validateField(formName); + }); scope.schemaError = function() { return error;