@@ -40,29 +40,6 @@ angular.module('schemaForm').provider('schemaFormDecorators',
4040 scope : true ,
4141 require : '?^sfSchema' ,
4242 link : function ( scope , element , attrs , sfSchema ) {
43- //rebind our part of the form to the scope.
44- var once = scope . $watch ( attrs . form , function ( form ) {
45-
46- if ( form ) {
47- scope . form = form ;
48-
49- //ok let's replace that template!
50- //We do this manually since we need to bind ng-model properly and also
51- //for fieldsets to recurse properly.
52- var url = templateUrl ( name , form ) ;
53- $http . get ( url , { cache : $templateCache } ) . then ( function ( res ) {
54- var key = form . key ?
55- sfPathProvider . stringify ( form . key ) . replace ( / " / g, '"' ) : '' ;
56- var template = res . data . replace (
57- / \$ \$ v a l u e \$ \$ / g,
58- 'model' + ( key [ 0 ] !== '[' ? '.' : '' ) + key
59- ) ;
60- element . html ( template ) ;
61- $compile ( element . contents ( ) ) ( scope ) ;
62- } ) ;
63- once ( ) ;
64- }
65- } ) ;
6643
6744 //Keep error prone logic from the template
6845 scope . showTitle = function ( ) {
@@ -158,8 +135,47 @@ angular.module('schemaForm').provider('schemaFormDecorators',
158135
159136 //Otherwise we only have input number not being a number
160137 return 'Not a number' ;
161-
162138 } ;
139+
140+ // Rebind our part of the form to the scope.
141+ var once = scope . $watch ( attrs . form , function ( form ) {
142+ if ( form ) {
143+ scope . form = form ;
144+
145+ //ok let's replace that template!
146+ //We do this manually since we need to bind ng-model properly and also
147+ //for fieldsets to recurse properly.
148+ var url = templateUrl ( name , form ) ;
149+ $http . get ( url , { cache : $templateCache } ) . then ( function ( res ) {
150+ var key = form . key ?
151+ sfPathProvider . stringify ( form . key ) . replace ( / " / g, '"' ) : '' ;
152+ var template = res . data . replace (
153+ / \$ \$ v a l u e \$ \$ / g,
154+ 'model' + ( key [ 0 ] !== '[' ? '.' : '' ) + key
155+ ) ;
156+ element . html ( template ) ;
157+
158+ // Do we have a condition? Then we slap on an ng-if on all children,
159+ // but be nice to existing ng-if.
160+ if ( form . condition ) {
161+ element . children ( ) . each ( function ( ) {
162+ var ngIf = this . getAttribute ( 'ng-if' ) ;
163+ this . setAttribute (
164+ 'ng-if' ,
165+ ngIf ?
166+ '(' + ngIf +
167+ ') || (evalExpr(form.condition,{ model: model, "arrayIndex": arrayIndex }))'
168+ : 'evalExpr(form.condition,{ model: model, "arrayIndex": arrayIndex })'
169+ ) ;
170+ } ) ;
171+ }
172+
173+ $compile ( element . contents ( ) ) ( scope ) ;
174+ } ) ;
175+
176+ once ( ) ;
177+ }
178+ } ) ;
163179 }
164180 } ;
165181 }
0 commit comments