You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 30, 2018. It is now read-only.
Formly for Angular is an AngularJS module which has directives to help customize and render JSON based forms. The directive originated from a need to allow our users to create surveys and distribute them easily. Currently we've can render the form data from JSON and assign a model to form so we can receive the submitted data.
//the key to be used in the result values {... "username": "johndoe" ... }
44
-
key:'username',
45
-
46
-
//default value
47
-
default:'uberuser'
48
-
type:'text',
49
-
label:'Username',
50
-
placeholder:'johndoe',
51
-
required:true,
52
-
disabled:false, //default: false
53
-
},
54
-
{
55
-
key:'password'
56
-
type:'password',
57
-
label:'Password',
58
-
required:true,
59
-
disabled:false, //default: false
60
-
}
61
-
62
-
];
63
-
64
-
$scope.formOptions= {
65
-
66
-
//Set the id of the form
67
-
uniqueFormId:'myFormId',
68
-
69
-
//Hide the submit button that is added automaticaly
70
-
//default: false
71
-
hideSubmit:false,
72
-
73
-
//Set the text on the default submit button
74
-
//default: Submit
75
-
submitCopy:'Login'
76
-
};
77
-
78
-
$scope.onSubmit=function() {
79
-
console.log('form submitted:', $scope.formData);
80
-
};
40
+
$scope.formData= {};
41
+
$scope.formFields= [
42
+
{
43
+
//the key to be used in the result values {... "username": "johndoe" ... }
44
+
key:'username',
45
+
46
+
//default value
47
+
default:'uberuser'
48
+
type:'text',
49
+
label:'Username',
50
+
placeholder:'johndoe',
51
+
required:true,
52
+
disabled:false, //default: false
53
+
},
54
+
{
55
+
key:'password'
56
+
type:'password',
57
+
label:'Password',
58
+
required:true,
59
+
disabled:false, //default: false
60
+
}
61
+
62
+
];
63
+
64
+
$scope.formOptions= {
65
+
66
+
//Set the id of the form
67
+
uniqueFormId:'myFormId',
68
+
69
+
//Hide the submit button that is added automaticaly
70
+
//default: false
71
+
hideSubmit:false,
72
+
73
+
//Set the text on the default submit button
74
+
//default: Submit
75
+
submitCopy:'Login'
76
+
};
77
+
78
+
$scope.onSubmit=function() {
79
+
console.log('form submitted:', $scope.formData);
80
+
};
81
81
```
82
82
83
83
### Creating Form Fields
@@ -143,54 +143,85 @@ When constructing fields use the options below to customize each field object. Y
143
143
>`undefined`
144
144
145
145
### Form Fields
146
+
Below is a detailed description of each form fields and its custom properties.
147
+
146
148
#### Text form field
147
149
>The text field allows single line input with a input element set to `type='text'`. It doesn't have any custom properties.
148
150
##### default (string)
149
151
150
152
_Example text field_
151
153
```json
152
-
{
153
-
"type": "text",
154
-
"key": "firstName",
155
-
"placeholder": "jane doe",
156
-
"label": "First name"
157
-
}
154
+
{
155
+
"type": "text",
156
+
"key": "firstName",
157
+
"placeholder": "jane doe",
158
+
"label": "First name"
159
+
}
158
160
```
159
161
160
162
---
161
163
#### Textarea form field
162
-
The textarea field creates multiline input with a textarea element.
164
+
>The textarea field creates multiline input with a textarea element.
163
165
##### default (string)
164
166
##### lines (number)
165
167
>`lines` sets the rows attribute for the textarea element.
166
168
167
169
_Example textarea field_
168
170
```json
169
-
{
170
-
"type": "textarea",
171
-
"key": "about",
172
-
"placeholder": "I like puppies",
173
-
"label": "Tell me about yourself",
174
-
"lines": 4
175
-
}
171
+
{
172
+
"type": "textarea",
173
+
"key": "about",
174
+
"placeholder": "I like puppies",
175
+
"label": "Tell me about yourself",
176
+
"lines": 4
177
+
}
176
178
```
177
179
178
180
---
179
181
#### Checkbox form field
180
-
The checkbox field allows checkbox input with a input element set to `type='checkbox'`. It doesn't have any custom properties.
182
+
>The checkbox field allows checkbox input with a input element set to `type='checkbox'`. It doesn't have any custom properties.
181
183
##### default (boolean)
182
184
183
185
_Example checkbox field_
184
186
```json
185
-
{
186
-
"type": "checkbox",
187
-
"key": "checkThis",
188
-
"label": "Check this box",
189
-
"default": true
190
-
}
187
+
{
188
+
"type": "checkbox",
189
+
"key": "checkThis",
190
+
"label": "Check this box",
191
+
"default": true
192
+
}
191
193
```
192
194
193
195
#### Radio form field
196
+
>The radio field allows multiple choice input with a series of linked inputs, with `type='radio'`.
197
+
##### default (string)
198
+
>The default should be set to the `value` of one of the `options`.
199
+
##### options (array)
200
+
>`options` is an array of options for the radio form field to display. Each option should be an object with a `name`(string) and `value`(string or number).
201
+
202
+
_Example radio field_
203
+
```json
204
+
{
205
+
"key": "triedEmber",
206
+
"type": "radio",
207
+
"label": "Have you tried EmberJs yet?",
208
+
"default": "no",
209
+
"options": [
210
+
{
211
+
"name": "Yes, and I love it!",
212
+
"value": "yesyes"
213
+
},
214
+
{
215
+
"name": "Yes, but I'm not a fan...",
216
+
"value": "yesno"
217
+
},
218
+
{
219
+
"name": "Nope",
220
+
"value": "no"
221
+
}
222
+
]
223
+
}
224
+
```
194
225
#### Select form field
195
226
#### Number form field
196
227
#### Password form field
@@ -205,11 +236,11 @@ _Example checkbox field_
205
236
## Development
206
237
207
238
1.`git checkout master`
208
-
1. run `npm install && bower install`
209
-
2. test your code using `grunt dev` which hosts the app at `http://localhost:4000`
210
-
3. commit your changes
239
+
1. run `npm install && bower install`
240
+
2. test your code using `grunt dev` which hosts the app at `http://localhost:4000`
241
+
3. commit your changes
211
242
3. update README, CHANGELOG, bower.json, and do any other final polishing to prepare for publishing
212
-
1. git commit changes
243
+
1. git commit changes
213
244
214
245
## Grunt targets
215
246
*`grunt dev`: Creates a server for testing at `http://0.0.0.0:4000`
0 commit comments