@@ -49,12 +49,12 @@ angular.module('formly.render').directive('formlyField', [
49
49
transclude : true ,
50
50
scope : {
51
51
optionsData : '&options' ,
52
- formId : '@ formId' ,
53
- index : '@ index' ,
52
+ formId : '= formId' ,
53
+ index : '= index' ,
54
54
value : '=formValue'
55
55
} ,
56
56
link : function fieldLink ( $scope , $element , $attr ) {
57
- var templateUrl = getTemplateUrl ( $scope . options . type ) ;
57
+ var templateUrl = $scope . options . templateUrl || getTemplateUrl ( $scope . options . type ) ;
58
58
if ( templateUrl ) {
59
59
$http . get ( templateUrl , { cache : $templateCache } ) . success ( function ( data ) {
60
60
//template data returned
@@ -69,7 +69,7 @@ angular.module('formly.render').directive('formlyField', [
69
69
'$scope' ,
70
70
function fieldController ( $scope ) {
71
71
$scope . options = $scope . optionsData ( ) ;
72
- if ( $scope . options . default ) {
72
+ if ( typeof $scope . options . default !== 'undefined' ) {
73
73
$scope . value = $scope . options . default ;
74
74
}
75
75
// set field id to link labels and fields
@@ -86,18 +86,11 @@ angular.module('formly.render').directive('formlyForm', function formlyForm() {
86
86
templateUrl : 'directives/formly-form.html' ,
87
87
replace : true ,
88
88
scope : {
89
- formId : '@formId' ,
90
89
fields : '=fields' ,
91
90
options : '=options' ,
92
91
result : '=result' ,
93
92
formOnParentScope : '=name'
94
93
} ,
95
- controller : [
96
- '$scope' ,
97
- '$element' ,
98
- function formController ( $scope , $element ) {
99
- }
100
- ] ,
101
94
compile : function ( scope , iElement , iAttrs , controller , transcludeFn ) {
102
95
return {
103
96
post : function ( scope , ele , attr , controller ) {
@@ -106,7 +99,22 @@ angular.module('formly.render').directive('formlyForm', function formlyForm() {
106
99
scope . formOnParentScope = scope [ attr . name ] ;
107
100
}
108
101
} ;
109
- }
102
+ } ,
103
+ controller : [
104
+ '$scope' ,
105
+ '$element' ,
106
+ '$parse' ,
107
+ function ( $scope , $element , $parse ) {
108
+ $scope . $watch ( 'result' , function ( newValue ) {
109
+ angular . forEach ( $scope . fields , function ( field , index ) {
110
+ if ( field . hideExpression ) {
111
+ var getter = $parse ( field . hideExpression ) ;
112
+ field . hide = getter ( $scope . result ) ;
113
+ }
114
+ } ) ;
115
+ } , true ) ;
116
+ }
117
+ ]
110
118
} ;
111
119
} ) ;
112
120
angular . module ( 'formly.render' ) . run ( [
@@ -123,6 +131,6 @@ angular.module('formly.render').run([
123
131
$templateCache . put ( 'directives/formly-field-text.html' , '<div class=form-group><label for={{id}}>{{options.label || \'Text\'}} {{options.required ? \'*\' : \'\'}}</label><input class=form-control id={{id}} placeholder={{options.placeholder}} ng-required=options.required ng-disabled=options.disabled ng-model=value></div>' ) ;
124
132
$templateCache . put ( 'directives/formly-field-textarea.html' , '<div class=form-group><label for={{id}}>{{options.label || \'Text\'}} {{options.required ? \'*\' : \'\'}}</label><textarea type=text class=form-control id={{id}} rows={{options.lines}} placeholder={{options.placeholder}} ng-required=options.required ng-disabled=options.disabled ng-model=value>\n' + '\t</textarea></div>' ) ;
125
133
$templateCache . put ( 'directives/formly-field.html' , '' ) ;
126
- $templateCache . put ( 'directives/formly-form.html' , '<form class=formly role=form><formly-field ng-repeat="field in fields" options=field form-value=result[field.key||$index] class=formly-field form-id={{ options.uniqueFormId}} index={{ $index}} ></formly-field><button type=submit ng-hide=options.hideSubmit>{{options.submitCopy || "Submit"}}</button></form>' ) ;
134
+ $templateCache . put ( 'directives/formly-form.html' , '<form class=formly role=form><formly-field ng-repeat="field in fields" options=field form-value=result[field.key||$index] class=formly-field form-id=options.uniqueFormId index=$index ng-hide=field.hide ></formly-field><button type=submit ng-hide=options.hideSubmit>{{options.submitCopy || "Submit"}}</button></form>' ) ;
127
135
}
128
136
] ) ;
0 commit comments