@@ -65,23 +65,50 @@ angular.module('formly.render').directive('formlyForm', [
65
65
'formlyOptions' ,
66
66
'$compile' ,
67
67
function formlyForm ( formlyOptions , $compile ) {
68
+ var templateHide = 'ng-hide="field.hide"' ;
69
+ var fieldsTemplate = [
70
+ '<formly-field ng-repeat="field in fields"' ,
71
+ 'options="field"' ,
72
+ 'form-result="result"' ,
73
+ 'form-value="result[field.key||$index]"' ,
74
+ 'form-id="options.uniqueFormId"' ,
75
+ 'ng-hide="field.hide"' ,
76
+ 'index="$index">' ,
77
+ '</formly-field>'
78
+ ] . join ( ' ' ) ;
68
79
return {
69
80
restrict : 'AE' ,
70
- templateUrl : 'directives/formly-form.html' ,
81
+ template : function ( el , attr ) {
82
+ var useNgIf = formlyOptions . getOptions ( ) . useNgIfToHide ;
83
+ return [
84
+ '<form class="formly" role="form">' ,
85
+ '<div class="ng-hide">fields</div>' ,
86
+ '<button type="submit"' ,
87
+ 'ng-show="!options.hideSubmit">' ,
88
+ '{{options.submitCopy || "Submit"}}' ,
89
+ '</button>' ,
90
+ '</form>'
91
+ ] . join ( ' ' ) ;
92
+ } ,
71
93
replace : true ,
72
94
scope : {
73
95
fields : '=' ,
74
96
options : '=?' ,
75
97
result : '=' ,
76
98
formOnParentScope : '=name'
77
99
} ,
78
- compile : function ( scope , iElement , iAttrs , controller , transcludeFn ) {
100
+ compile : function ( ) {
79
101
return {
80
102
post : function ( scope , ele , attr , controller ) {
81
103
scope . options = angular . extend ( formlyOptions . getOptions ( ) , scope . options ) ;
82
104
if ( scope . options . submitButtonTemplate ) {
83
105
ele . find ( 'button' ) . replaceWith ( $compile ( scope . options . submitButtonTemplate ) ( scope ) ) ;
84
106
}
107
+ var template = fieldsTemplate ;
108
+ if ( scope . options . useNgIfToHide ) {
109
+ template = template . replace ( templateHide , 'ng-if="!field.hide"' ) ;
110
+ }
111
+ ele . find ( 'div' ) . replaceWith ( $compile ( template ) ( scope ) ) ;
85
112
//Post gets called after angular has created the FormController
86
113
//Now pass the FormController back up to the parent scope
87
114
scope . formOnParentScope = scope [ attr . name ] ;
@@ -134,7 +161,8 @@ angular.module('formly.render').provider('formlyOptions', function () {
134
161
uniqueFormId : null ,
135
162
submitCopy : 'Submit' ,
136
163
hideSubmit : false ,
137
- submitButtonTemplate : null
164
+ submitButtonTemplate : null ,
165
+ useNgIfToHide : false
138
166
} ;
139
167
function setOption ( name , value ) {
140
168
if ( typeof name === 'string' ) {
0 commit comments