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

Commit 3b936c2

Browse files
committed
merged jhr007s newFeatures pull request
2 parents 6176964 + 6bfcb18 commit 3b936c2

File tree

7 files changed

+79
-17
lines changed

7 files changed

+79
-17
lines changed

dist/formly.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,24 @@ angular.module('formly.render').directive('formlyForm', function formlyForm() {
8989
formId: '@formId',
9090
fields: '=fields',
9191
options: '=options',
92-
result: '=result'
92+
result: '=result',
93+
formOnParentScope: '=name'
9394
},
9495
controller: [
9596
'$scope',
9697
'$element',
9798
function formController($scope, $element) {
9899
}
99-
]
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+
}
100110
};
101111
});
102112
angular.module('formly.render').run([
@@ -113,6 +123,6 @@ angular.module('formly.render').run([
113123
$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>');
114124
$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>');
115125
$templateCache.put('directives/formly-field.html', '');
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>');
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>');
117127
}
118128
]);

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<form class="formly" role="form" name="{{options.uniqueFormId}}">
1+
<form class="formly" role="form">
22
<formly-field ng-repeat="field in fields"
33
options="field"
44
form-value="result[field.key||$index]"

src/directives/formly-form.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,19 @@ angular.module('formly.render')
99
formId: '@formId',
1010
fields: '=fields',
1111
options: '=options',
12-
result: '=result'
12+
result: '=result',
13+
formOnParentScope: '=name'
1314
},
1415
controller: function formController($scope, $element) {
15-
16+
},
17+
compile: function (scope, iElement, iAttrs, controller, transcludeFn) {
18+
return {
19+
post: function (scope, ele, attr, controller) {
20+
//Post gets called after angular has created the FormController
21+
//Now pass the FormController back up to the parent scope
22+
scope.formOnParentScope = scope[attr.name];
23+
}
24+
}
1625
}
1726
};
1827
});

src/views/home.html

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,50 @@ <h3>Fields</h3>
5757
<div class="col-sm-4 col-md-4 col-lg-4">
5858

5959
<h3>Form</h3>
60-
<formly-form result="formData"
60+
<formly-form name="myFormName"
61+
result="formData"
6162
fields="formFields"
6263
options="formOptions"
6364
ng-submit="onSubmit()">
6465
</formly-form>
6566
</div>
6667
<div class="col-sm-4 col-md-4 col-lg-4">
6768

68-
<h3>Form Data</h3>
69+
<h3>Submitted Data</h3>
70+
<div hljs source="formData|json"></div>
6971

70-
<div hljs source="toPrettyJSON(formData, 4)"></div>
72+
<h3>Form State</h3>
73+
<table class="table table-condensed">
74+
<thead>
75+
<tr>
76+
<th>State</th>
77+
<th>Value</th>
78+
</tr>
79+
</thead>
80+
<tbody>
81+
<tr>
82+
<td>$pristine</td>
83+
<td>{{myFormName.$pristine}}</td>
84+
</tr>
85+
<tr>
86+
<td>$dirty</td>
87+
<td>{{myFormName.$dirty}}</td>
88+
</tr>
89+
<tr>
90+
<td>$valid</td>
91+
<td>{{myFormName.$valid}}</td>
92+
</tr>
93+
<tr>
94+
<td>$invalid</td>
95+
<td>{{myFormName.$invalid}}</td>
96+
</tr>
97+
<tr>
98+
<td>$error</td>
99+
<td>{{myFormName.$error}}</td>
100+
</tr>
101+
</tbody>
102+
103+
</table>
71104
</div>
72105
</div>
73106
</div>

src/views/home.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,30 @@ app.controller('home', function($scope, $parse, $rootScope) {
3434
$scope.formOptionsError = true;
3535
}
3636
});
37-
37+
3838
// Public Vars
3939
$scope.formFields = [{
40-
type: 'email',
41-
placeholder: '[email protected]',
42-
key: 'email'
43-
}, {
40+
key: 'firstName',
4441
type: 'text',
4542
label: 'First Name',
4643
placeholder: 'Jane'
4744
}, {
45+
key: 'lastName',
4846
type: 'text',
4947
label: 'Last Name',
5048
placeholder: 'Doe'
5149
}, {
50+
key: 'email',
51+
type: 'email',
52+
placeholder: '[email protected]'
53+
}, {
54+
key: 'about',
5255
type: 'textarea',
5356
label: 'Tell me about yourself',
5457
placeholder: 'I like puppies',
5558
lines: 4
5659
}, {
60+
key: 'triedEmber',
5761
type: 'radio',
5862
label: 'Have you tried EmberJs yet?',
5963
default: 'no',
@@ -70,19 +74,22 @@ app.controller('home', function($scope, $parse, $rootScope) {
7074
}
7175
]
7276
}, {
77+
key: 'angularFan',
7378
type: 'text',
7479
label: 'Angular Fan?',
7580
disabled: true,
7681
default: 'yes',
7782
required: true
7883
}, {
84+
key: 'love',
7985
type: 'number',
8086
label: 'How much love?',
8187
default: 2,
8288
min: 0,
8389
max: 100,
8490
required: true
8591
}, {
92+
key: 'transportation',
8693
type: 'select',
8794
label: 'How do you get around in the city',
8895
options: [
@@ -119,17 +126,20 @@ app.controller('home', function($scope, $parse, $rootScope) {
119126
}
120127
]
121128
}, {
129+
key: 'password',
122130
type: 'password',
123131
label: 'Password'
124132
}, {
133+
key: 'checkThis',
125134
type: 'checkbox',
126135
label: 'Check this here'
127136
}, {
137+
key:'secretCode',
128138
type: 'hidden',
129139
default: 'secret_code'
130140
}];
141+
131142
$scope.formOptions = {
132-
uniqueFormId: 'simpleform',
133143
submitCopy: 'Save'
134144
};
135145
$scope.submittedData = null;

0 commit comments

Comments
 (0)