Skip to content
This repository was archived by the owner on Apr 30, 2018. It is now read-only.

Commit 8f39d70

Browse files
committed
Added two way binding to the variable passed into the result attribute
Removed populateResult because it breaks the two-way binding
1 parent e7192f9 commit 8f39d70

File tree

6 files changed

+8
-52
lines changed

6 files changed

+8
-52
lines changed

dist/formly.js

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -95,27 +95,6 @@ angular.module('formly.render').directive('formlyForm', function formlyForm() {
9595
'$scope',
9696
'$element',
9797
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-
};
11998
}
12099
]
121100
};
@@ -134,6 +113,6 @@ angular.module('formly.render').run([
134113
$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>');
135114
$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>');
136115
$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>');
116+
$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=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>');
138117
}
139118
]);

dist/formly.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/formly.min.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/directives/formly-form.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<form class="formly" role="form" name="{{options.uniqueFormId}}">
22
<formly-field ng-repeat="field in fields"
33
options="field"
4-
form-value="value"
4+
form-value="result[field.key||$index]"
55
class="formly-field"
66
form-id="{{options.uniqueFormId}}"
77
index="{{$index}}">
88
</formly-field>
99
<button type="submit"
10-
ng-hide="options.hideSubmit"
11-
ng-click="populateResult()">
10+
ng-hide="options.hideSubmit">
1211
{{options.submitCopy || "Submit"}}
1312
</button>
1413
</form>

src/directives/formly-form.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,6 @@ angular.module('formly.render')
1313
},
1414
controller: function formController($scope, $element) {
1515

16-
$scope.populateResult = function() {
17-
var formChildren = $element.children();
18-
var fieldScope;
19-
angular.forEach(formChildren, function(fieldElement, key){
20-
// grab fields isolate scope
21-
fieldScope = angular.element(fieldElement).scope();
22-
23-
// check if its a form field, otherwise ignore, ie its the button
24-
if (fieldScope.field) {
25-
// if a key is set, then save the data with that key in the result object
26-
// otherwise use the field's index from the fields array
27-
var dataKey;
28-
if('key' in fieldScope.field) {
29-
dataKey = fieldScope.field.key;
30-
} else {
31-
dataKey = fieldScope.$index;
32-
}
33-
34-
// set value in result
35-
$scope.result[dataKey] = fieldScope.value;
36-
}
37-
});
38-
};
3916
}
4017
};
4118
});

src/views/home.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ <h3>Form</h3>
6565
</div>
6666
<div class="col-sm-4 col-md-4 col-lg-4">
6767

68-
<h3>Submitted Data</h3>
69-
<div hljs source="toPrettyJSON(submittedData, 4)"></div>
68+
<h3>Form Data</h3>
69+
70+
<div hljs source="toPrettyJSON(formData, 4)"></div>
7071
</div>
7172
</div>
7273
</div>

0 commit comments

Comments
 (0)