Skip to content

Commit e29b688

Browse files
committed
Merge branch 'hotfix/not-until-rendered'
2 parents 9d2868e + d31ab92 commit e29b688

File tree

7 files changed

+36
-12
lines changed

7 files changed

+36
-12
lines changed

Diff for: CHANGELOG

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
v0.8.11
2+
-------
3+
* Bugfix for checkboxes validation in the new builder.
4+
15
v0.8.10
26
-------
37
* Bugfix for checkboxes when model array is undefined.

Diff for: dist/schema-form.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -2278,7 +2278,10 @@ 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+
if (scope.ngModel && scope.ngModel.$pristine && scope.firstDigest &&
2282+
(!scope.options || scope.options.validateOnRender !== true)) {
2283+
return;
2284+
} else if (scope.validateField) {
22822285
scope.validateField();
22832286
}
22842287
};
@@ -2620,6 +2623,16 @@ angular.module('schemaForm')
26202623
var lookup = Object.create(null);
26212624
scope.lookup(lookup); // give the new lookup to the controller.
26222625
element[0].appendChild(sfBuilder.build(merged, decorator, slots, lookup));
2626+
2627+
// We need to know if we're in the first digest looping
2628+
// I.e. just rendered the form so we know not to validate
2629+
// empty fields.
2630+
childScope.firstDigest = true;
2631+
// We use a ordinary timeout since we don't need a digest after this.
2632+
setTimeout(function() {
2633+
childScope.firstDigest = false;
2634+
}, 0);
2635+
26232636
//compile only children
26242637
$compile(element.children())(childScope);
26252638

@@ -2837,14 +2850,11 @@ angular.module('schemaForm').directive('schemaValidate', ['sfValidator', '$parse
28372850
}
28382851
};
28392852

2840-
var first = true;
28412853
ngModel.$formatters.push(function(val) {
2842-
28432854
// When a form first loads this will be called for each field.
28442855
// we usually don't want that.
2845-
if (ngModel.$pristine && first &&
2856+
if (ngModel.$pristine && scope.firstDigest &&
28462857
(!scope.options || scope.options.validateOnRender !== true)) {
2847-
first = false;
28482858
return val;
28492859
}
28502860
validate(ngModel.$modelValue);

Diff for: 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.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-schema-form",
3-
"version": "0.8.10",
3+
"version": "0.8.11",
44
"description": "Create complex forms from a JSON schema with angular.",
55
"repository": "Textalk/angular-schema-form",
66
"main": "dist/schema-form.min.js",

Diff for: 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
};

Diff for: 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

Diff for: 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)