Skip to content

Commit

Permalink
Merge branch 'hotfix/not-until-rendered'
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlgj committed Sep 25, 2015
2 parents 9d2868e + d31ab92 commit e29b688
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
@@ -1,3 +1,7 @@
v0.8.11
-------
* Bugfix for checkboxes validation in the new builder.

v0.8.10
-------
* Bugfix for checkboxes when model array is undefined.
Expand Down
20 changes: 15 additions & 5 deletions dist/schema-form.js
Expand Up @@ -2278,7 +2278,10 @@ function(sel, sfPath, schemaForm) {
//scope.modelArray = modelArray;
scope.modelArray = scope.$eval(attrs.sfNewArray);
// validateField method is exported by schema-validate
if (scope.validateField) {
if (scope.ngModel && scope.ngModel.$pristine && scope.firstDigest &&
(!scope.options || scope.options.validateOnRender !== true)) {
return;
} else if (scope.validateField) {
scope.validateField();
}
};
Expand Down Expand Up @@ -2620,6 +2623,16 @@ angular.module('schemaForm')
var lookup = Object.create(null);
scope.lookup(lookup); // give the new lookup to the controller.
element[0].appendChild(sfBuilder.build(merged, decorator, slots, lookup));

// We need to know if we're in the first digest looping
// I.e. just rendered the form so we know not to validate
// empty fields.
childScope.firstDigest = true;
// We use a ordinary timeout since we don't need a digest after this.
setTimeout(function() {
childScope.firstDigest = false;
}, 0);

//compile only children
$compile(element.children())(childScope);

Expand Down Expand Up @@ -2837,14 +2850,11 @@ angular.module('schemaForm').directive('schemaValidate', ['sfValidator', '$parse
}
};

var first = true;
ngModel.$formatters.push(function(val) {

// When a form first loads this will be called for each field.
// we usually don't want that.
if (ngModel.$pristine && first &&
if (ngModel.$pristine && scope.firstDigest &&
(!scope.options || scope.options.validateOnRender !== true)) {
first = false;
return val;
}
validate(ngModel.$modelValue);
Expand Down
2 changes: 1 addition & 1 deletion dist/schema-form.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "angular-schema-form",
"version": "0.8.10",
"version": "0.8.11",
"description": "Create complex forms from a JSON schema with angular.",
"repository": "Textalk/angular-schema-form",
"main": "dist/schema-form.min.js",
Expand Down
5 changes: 4 additions & 1 deletion src/directives/newArray.js
Expand Up @@ -18,7 +18,10 @@ function(sel, sfPath, schemaForm) {
//scope.modelArray = modelArray;
scope.modelArray = scope.$eval(attrs.sfNewArray);
// validateField method is exported by schema-validate
if (scope.validateField) {
if (scope.ngModel && scope.ngModel.$pristine && scope.firstDigest &&
(!scope.options || scope.options.validateOnRender !== true)) {
return;
} else if (scope.validateField) {
scope.validateField();
}
};
Expand Down
10 changes: 10 additions & 0 deletions src/directives/schema-form.js
Expand Up @@ -118,6 +118,16 @@ angular.module('schemaForm')
var lookup = Object.create(null);
scope.lookup(lookup); // give the new lookup to the controller.
element[0].appendChild(sfBuilder.build(merged, decorator, slots, lookup));

// We need to know if we're in the first digest looping
// I.e. just rendered the form so we know not to validate
// empty fields.
childScope.firstDigest = true;
// We use a ordinary timeout since we don't need a digest after this.
setTimeout(function() {
childScope.firstDigest = false;
}, 0);

//compile only children
$compile(element.children())(childScope);

Expand Down
5 changes: 1 addition & 4 deletions src/directives/schema-validate.js
Expand Up @@ -141,14 +141,11 @@ angular.module('schemaForm').directive('schemaValidate', ['sfValidator', '$parse
}
};

var first = true;
ngModel.$formatters.push(function(val) {

// When a form first loads this will be called for each field.
// we usually don't want that.
if (ngModel.$pristine && first &&
if (ngModel.$pristine && scope.firstDigest &&
(!scope.options || scope.options.validateOnRender !== true)) {
first = false;
return val;
}
validate(ngModel.$modelValue);
Expand Down

0 comments on commit e29b688

Please sign in to comment.