@@ -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 ) ;
0 commit comments