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

Commit 4bbac6b

Browse files
committed
progress on documenting formly fields
1 parent dc11d15 commit 4bbac6b

File tree

1 file changed

+112
-4
lines changed

1 file changed

+112
-4
lines changed

README.md

Lines changed: 112 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@ See `bower.json` and `index.html` in the `master` branch for a full list / more
2929

3030
## Documentation
3131

32+
You can add a formly-form in your HTML templates as shown below.
3233
```html
3334
<formly-form result="formData" fields="formFields" options="formOptions" ng-submit="onSubmit()">
3435
</formly-form>
3536
```
3637

37-
For options specific to input types see their directive html in `src/directives`
38+
Example data as it would be set in the controller
3839
```javascript
39-
var formFields = [
40+
$scope.formData = {};
41+
$scope.formFields = [
4042
{
4143
//the key to be used in the result values {... "username": "johndoe" ... }
4244
key: 'username',
@@ -59,7 +61,7 @@ For options specific to input types see their directive html in `src/directives`
5961

6062
];
6163

62-
var formOptions = {
64+
$scope.formOptions = {
6365

6466
//Set the id of the form
6567
uniqueFormId: 'myFormId',
@@ -72,7 +74,113 @@ For options specific to input types see their directive html in `src/directives`
7274
//default: Submit
7375
submitCopy: 'Login'
7476
};
75-
```
77+
78+
$scope.onSubmit = function() {
79+
console.log('form submitted:', $scope.formData);
80+
};
81+
```
82+
83+
### Creating Form Fields
84+
When constructing fields use the options below to customize each field object. You must set at least a `type` or `templateUrl`.
85+
86+
##### type (string)
87+
`type` is the type of field to be rendered. Either type or templateUrl must be set.
88+
89+
###### Default
90+
`null`
91+
92+
###### Values
93+
[`text`](#text-form-field), [`textarea`](#textarea-form-field), `radio`, `select`, `number`, `checkbox`, `password`, `hidden`, `email`, `text`
94+
95+
---
96+
##### templateUrl (string)
97+
`templateUrl` can be set instead of `type` to use a custom html template form field. Set a path relative to the root of the application. ie `directives/custom-field.html`
98+
99+
###### Default
100+
`undefined`
101+
102+
---
103+
##### key (string)
104+
By default form results are keyed by location in the form array, you can override this by specifying a `key`.
105+
106+
###### Default
107+
`undefined`
108+
109+
---
110+
##### label (string)
111+
`label` is used to add an html label to each field.
112+
113+
###### Default
114+
A default is set for each field based on its type. ie `Text`, `Checkbox`, `Password`
115+
116+
---
117+
##### required (boolean)
118+
`required` is used to add the required attribute to a form field.
119+
120+
###### Default
121+
`undefined`
122+
123+
---
124+
##### disabled (boolean)
125+
`disabled` is used to add the disabled attribute to a form field.
126+
127+
###### Default
128+
`undefined`
129+
130+
---
131+
##### placeholder (string)
132+
`placeholder` is used to add placeholder text to some inputs.
133+
134+
###### Default
135+
`undefined`
136+
137+
### Form Fields
138+
#### Text form field
139+
The text field allows single line input with a input element set to `type='text'`. It doesn't have any custom properties.
140+
##### default (string)
141+
142+
_Example text field_
143+
```json
144+
{
145+
"type": "text",
146+
"key": "firstName",
147+
"placeholder": "jane doe",
148+
"label": "First name"
149+
}
150+
```
151+
152+
---
153+
#### Textarea form field
154+
The textarea field creates multiline input with a textarea element.
155+
##### default (string)
156+
##### lines (number)
157+
`lines` sets the rows attribute for the textarea element.
158+
159+
_Example textarea field_
160+
```json
161+
{
162+
"type": "textarea",
163+
"key": "about",
164+
"placeholder": "I like puppies",
165+
"label": "Tell me about yourself",
166+
"lines": 4
167+
}
168+
```
169+
170+
---
171+
#### Checkbox form field
172+
The checkbox field allows checkbox input with a input element set to `type='checkbox'`. It doesn't have any custom properties.
173+
##### default (boolean)
174+
175+
_Example checkbox field_
176+
```json
177+
{
178+
"type": "checkbox",
179+
"key": "checkThis",
180+
"label": "Check this box",
181+
"default": true
182+
}
183+
```
76184

77185
## Roadmap
78186

0 commit comments

Comments
 (0)