@@ -7,6 +7,32 @@ function(decoratorsProvider, sfBuilderProvider, sfPathProvider) {
77 var ngModel = sfBuilderProvider . builders . ngModel ;
88 var sfField = sfBuilderProvider . builders . sfField ;
99
10+ var condition = function ( args ) {
11+ // Do we have a condition? Then we slap on an ng-if on all children,
12+ // but be nice to existing ng-if.
13+ if ( args . form . condition ) {
14+ var evalExpr = 'evalExpr(' + args . path + '.contidion, { model: model, "arrayIndex": $index})' ;
15+ if ( args . form . key ) {
16+ var strKey = sfPathProvider . stringify ( args . form . key ) ;
17+ evalExpr = 'evalExpr(' + args . path + '.condition,{ model: model, "arrayIndex": $index, ' +
18+ '"modelValue": model' + ( strKey [ 0 ] === '[' ? '' : '.' ) + strKey + '})' ;
19+ }
20+
21+ var children = args . fieldFrag . children ;
22+ for ( var i = 0 ; i < children . length ; i ++ ) {
23+ var child = children [ i ] ;
24+ var ngIf = child . getAttribute ( 'ng-if' ) ;
25+ child . setAttribute (
26+ 'ng-if' ,
27+ ngIf ?
28+ '(' + ngIf +
29+ ') || (' + evalExpr + ')'
30+ : evalExpr
31+ ) ;
32+ }
33+ }
34+ } ;
35+
1036 var array = function ( args ) {
1137 var items = args . fieldFrag . querySelector ( '[schema-form-array-items]' ) ;
1238 if ( items ) {
@@ -51,19 +77,19 @@ function(decoratorsProvider, sfBuilderProvider, sfPathProvider) {
5177 }
5278 } ;
5379
54- var defaults = [ sfField , ngModel , ngModelOptions ] ;
80+ var defaults = [ sfField , ngModel , ngModelOptions , condition ] ;
5581 decoratorsProvider . defineDecorator ( 'bootstrapDecorator' , {
5682 textarea : { template : base + 'textarea.html' , builder : defaults } ,
57- fieldset : { template : base + 'fieldset.html' , builder : [ sfField , simpleTransclusion ] } ,
58- array : { template : base + 'array.html' , builder : [ sfField , ngModelOptions , ngModel , array ] } ,
59- tabarray : { template : base + 'tabarray.html' , builder : [ sfField , ngModelOptions , ngModel , array ] } ,
60- tabs : { template : base + 'tabs.html' , builder : [ sfField , ngModelOptions , ngModel , tabs ] } ,
61- section : { template : base + 'section.html' , builder : [ sfField , simpleTransclusion ] } ,
62- conditional : { template : base + 'section.html' , builder : [ sfField , simpleTransclusion ] } ,
83+ fieldset : { template : base + 'fieldset.html' , builder : [ sfField , simpleTransclusion , condition ] } ,
84+ array : { template : base + 'array.html' , builder : [ sfField , ngModelOptions , ngModel , array , condition ] } ,
85+ tabarray : { template : base + 'tabarray.html' , builder : [ sfField , ngModelOptions , ngModel , array , condition ] } ,
86+ tabs : { template : base + 'tabs.html' , builder : [ sfField , ngModelOptions , ngModel , tabs , condition ] } ,
87+ section : { template : base + 'section.html' , builder : [ sfField , simpleTransclusion , condition ] } ,
88+ conditional : { template : base + 'section.html' , builder : [ sfField , simpleTransclusion , condition ] } ,
6389 actions : { template : base + 'actions.html' , builder : defaults } ,
6490 select : { template : base + 'select.html' , builder : defaults } ,
6591 checkbox : { template : base + 'checkbox.html' , builder : defaults } ,
66- checkboxes : { template : base + 'checkboxes.html' , builder : [ sfField , ngModelOptions , ngModel , array ] } ,
92+ checkboxes : { template : base + 'checkboxes.html' , builder : [ sfField , ngModelOptions , ngModel , array , condition ] } ,
6793 number : { template : base + 'default.html' , builder : defaults } ,
6894 password : { template : base + 'default.html' , builder : defaults } ,
6995 submit : { template : base + 'submit.html' , builder : defaults } ,
0 commit comments