@@ -7,6 +7,32 @@ function(decoratorsProvider, sfBuilderProvider, sfPathProvider) {
7
7
var ngModel = sfBuilderProvider . builders . ngModel ;
8
8
var sfField = sfBuilderProvider . builders . sfField ;
9
9
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
+
10
36
var array = function ( args ) {
11
37
var items = args . fieldFrag . querySelector ( '[schema-form-array-items]' ) ;
12
38
if ( items ) {
@@ -51,19 +77,19 @@ function(decoratorsProvider, sfBuilderProvider, sfPathProvider) {
51
77
}
52
78
} ;
53
79
54
- var defaults = [ sfField , ngModel , ngModelOptions ] ;
80
+ var defaults = [ sfField , ngModel , ngModelOptions , condition ] ;
55
81
decoratorsProvider . defineDecorator ( 'bootstrapDecorator' , {
56
82
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 ] } ,
63
89
actions : { template : base + 'actions.html' , builder : defaults } ,
64
90
select : { template : base + 'select.html' , builder : defaults } ,
65
91
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 ] } ,
67
93
number : { template : base + 'default.html' , builder : defaults } ,
68
94
password : { template : base + 'default.html' , builder : defaults } ,
69
95
submit : { template : base + 'submit.html' , builder : defaults } ,
0 commit comments