Skip to content

Commit a4d80eb

Browse files
committed
Merge pull request #656 from LeonardoGentile/feature-655
Pass optional form name when broadcast error
2 parents 012a311 + 0a87024 commit a4d80eb

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/directives/field.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,20 @@ angular.module('schemaForm').directive('sfField',
161161
// It looks better with dot notation.
162162
scope.$on(
163163
'schemaForm.error.' + form.key.join('.'),
164-
function(event, error, validationMessage, validity) {
164+
function(event, error, validationMessage, validity, formName) {
165+
// validationMessage and validity are mutually exclusive
166+
formName = validity;
165167
if (validationMessage === true || validationMessage === false) {
166168
validity = validationMessage;
167169
validationMessage = undefined;
168170
}
169171

172+
// If we have specified a form name, and this model is not within
173+
// that form, then leave things be.
174+
if(formName != undefined && scope.ngModel.$$parentForm.$name !== formName) {
175+
return;
176+
}
177+
170178
if (scope.ngModel && error) {
171179
if (scope.ngModel.$setDirty) {
172180
scope.ngModel.$setDirty();

src/services/decorators.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,20 @@ angular.module('schemaForm').provider('schemaFormDecorators',
229229
// It looks better with dot notation.
230230
scope.$on(
231231
'schemaForm.error.' + form.key.join('.'),
232-
function(event, error, validationMessage, validity) {
232+
function(event, error, validationMessage, validity, formName) {
233+
// validationMessage and validity are mutually exclusive
234+
formName = validity;
233235
if (validationMessage === true || validationMessage === false) {
234236
validity = validationMessage;
235237
validationMessage = undefined;
236238
}
237239

240+
// If we have specified a form name, and this model is not within
241+
// that form, then leave things be.
242+
if(formName != undefined && scope.ngModel.$$parentForm.$name !== formName) {
243+
return;
244+
}
245+
238246
if (scope.ngModel && error) {
239247
if (scope.ngModel.$setDirty) {
240248
scope.ngModel.$setDirty();

0 commit comments

Comments
 (0)