Skip to content

Commit e69cb4c

Browse files
committed
fNewArray also needs to honor the pristine rules.
1 parent 9d2868e commit e69cb4c

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed

dist/schema-form.js

+17-4
Original file line numberDiff line numberDiff line change
@@ -2278,7 +2278,11 @@ function(sel, sfPath, schemaForm) {
22782278
//scope.modelArray = modelArray;
22792279
scope.modelArray = scope.$eval(attrs.sfNewArray);
22802280
// validateField method is exported by schema-validate
2281-
if (scope.validateField) {
2281+
console.warn('first! watchFn ', scope.firstDigest)
2282+
if (scope.ngModel && scope.ngModel.$pristine && scope.firstDigest &&
2283+
(!scope.options || scope.options.validateOnRender !== true)) {
2284+
return;
2285+
} else if (scope.validateField) {
22822286
scope.validateField();
22832287
}
22842288
};
@@ -2620,6 +2624,16 @@ angular.module('schemaForm')
26202624
var lookup = Object.create(null);
26212625
scope.lookup(lookup); // give the new lookup to the controller.
26222626
element[0].appendChild(sfBuilder.build(merged, decorator, slots, lookup));
2627+
2628+
// We need to know if we're in the first digest looping
2629+
// I.e. just rendered the form so we know not to validate
2630+
// empty fields.
2631+
childScope.firstDigest = true;
2632+
// We use a ordinary timeout since we don't need a digest after this.
2633+
setTimeout(function() {
2634+
childScope.firstDigest = false;
2635+
}, 0);
2636+
26232637
//compile only children
26242638
$compile(element.children())(childScope);
26252639

@@ -2837,14 +2851,13 @@ angular.module('schemaForm').directive('schemaValidate', ['sfValidator', '$parse
28372851
}
28382852
};
28392853

2840-
var first = true;
28412854
ngModel.$formatters.push(function(val) {
28422855

28432856
// When a form first loads this will be called for each field.
28442857
// we usually don't want that.
2845-
if (ngModel.$pristine && first &&
2858+
2859+
if (ngModel.$pristine && scope.firstDigest &&
28462860
(!scope.options || scope.options.validateOnRender !== true)) {
2847-
first = false;
28482861
return val;
28492862
}
28502863
validate(ngModel.$modelValue);

dist/schema-form.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/directives/newArray.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ function(sel, sfPath, schemaForm) {
1818
//scope.modelArray = modelArray;
1919
scope.modelArray = scope.$eval(attrs.sfNewArray);
2020
// validateField method is exported by schema-validate
21-
if (scope.validateField) {
21+
if (scope.ngModel && scope.ngModel.$pristine && scope.firstDigest &&
22+
(!scope.options || scope.options.validateOnRender !== true)) {
23+
return;
24+
} else if (scope.validateField) {
2225
scope.validateField();
2326
}
2427
};

src/directives/schema-form.js

+10
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,16 @@ angular.module('schemaForm')
118118
var lookup = Object.create(null);
119119
scope.lookup(lookup); // give the new lookup to the controller.
120120
element[0].appendChild(sfBuilder.build(merged, decorator, slots, lookup));
121+
122+
// We need to know if we're in the first digest looping
123+
// I.e. just rendered the form so we know not to validate
124+
// empty fields.
125+
childScope.firstDigest = true;
126+
// We use a ordinary timeout since we don't need a digest after this.
127+
setTimeout(function() {
128+
childScope.firstDigest = false;
129+
}, 0);
130+
121131
//compile only children
122132
$compile(element.children())(childScope);
123133

src/directives/schema-validate.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,11 @@ angular.module('schemaForm').directive('schemaValidate', ['sfValidator', '$parse
141141
}
142142
};
143143

144-
var first = true;
145144
ngModel.$formatters.push(function(val) {
146-
147145
// When a form first loads this will be called for each field.
148146
// we usually don't want that.
149-
if (ngModel.$pristine && first &&
147+
if (ngModel.$pristine && scope.firstDigest &&
150148
(!scope.options || scope.options.validateOnRender !== true)) {
151-
first = false;
152149
return val;
153150
}
154151
validate(ngModel.$modelValue);

0 commit comments

Comments
 (0)