@@ -89,35 +89,24 @@ angular.module('formly.render').directive('formlyForm', function formlyForm() {
89
89
formId : '@formId' ,
90
90
fields : '=fields' ,
91
91
options : '=options' ,
92
- result : '=result'
92
+ result : '=result' ,
93
+ formOnParentScope : '=name'
93
94
} ,
94
95
controller : [
95
96
'$scope' ,
96
97
'$element' ,
97
98
function formController ( $scope , $element ) {
98
- $scope . populateResult = function ( ) {
99
- var formChildren = $element . children ( ) ;
100
- var fieldScope ;
101
- angular . forEach ( formChildren , function ( fieldElement , key ) {
102
- // grab fields isolate scope
103
- fieldScope = angular . element ( fieldElement ) . scope ( ) ;
104
- // check if its a form field, otherwise ignore, ie its the button
105
- if ( fieldScope . field ) {
106
- // if a key is set, then save the data with that key in the result object
107
- // otherwise use the field's index from the fields array
108
- var dataKey ;
109
- if ( 'key' in fieldScope . field ) {
110
- dataKey = fieldScope . field . key ;
111
- } else {
112
- dataKey = fieldScope . $index ;
113
- }
114
- // set value in result
115
- $scope . result [ dataKey ] = fieldScope . value ;
116
- }
117
- } ) ;
118
- } ;
119
99
}
120
- ]
100
+ ] ,
101
+ compile : function ( scope , iElement , iAttrs , controller , transcludeFn ) {
102
+ return {
103
+ post : function ( scope , ele , attr , controller ) {
104
+ //Post gets called after angular has created the FormController
105
+ //Now pass the FormController back up to the parent scope
106
+ scope . formOnParentScope = scope [ attr . name ] ;
107
+ }
108
+ } ;
109
+ }
121
110
} ;
122
111
} ) ;
123
112
angular . module ( 'formly.render' ) . run ( [
@@ -134,6 +123,6 @@ angular.module('formly.render').run([
134
123
$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>' ) ;
135
124
$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>' ) ;
136
125
$templateCache . put ( 'directives/formly-field.html' , '' ) ;
137
- $templateCache . put ( 'directives/formly-form.html' , '<form class=formly role=form name={{options.uniqueFormId}} ><formly-field ng-repeat="field in fields" options=field form-value=value class=formly-field form-id={{options.uniqueFormId}} index={{$index}}></formly-field><button type=submit ng-hide=options.hideSubmit ng-click=populateResult() >{{options.submitCopy || "Submit"}}</button></form>' ) ;
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>' ) ;
138
127
}
139
128
] ) ;
0 commit comments