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
@@ -4,28 +4,203 @@ import DocPage from '@docs/doc-page';
4
4
5
5
# Introduction
6
6
7
+
## Schema definition
8
+
9
+
A schema is an object consists of fields:
10
+
11
+
```jsx
12
+
{
13
+
fields: []
14
+
}
15
+
```
16
+
17
+
Other attribues, such as title or description, can be used in [form templates](/components/form-template).
18
+
19
+
## Field defitinion
20
+
7
21
```jsx
8
22
{
9
23
// required
10
-
component:'',
11
-
name:'',
24
+
component:'text-field',
25
+
name:'login',
12
26
// optional
13
-
validate: [],
27
+
actions: { ... },
14
28
clearedValue:null,
29
+
clearOnUnmount:true,
30
+
condition: { ... },
31
+
dataType:'string',
15
32
hideField:true,
16
33
initializeOnMount:true,
17
-
clearOnUnmount:true,
18
-
actions: {}
34
+
initialValue:'default-login'
35
+
validate: [ ... ],
19
36
// + component specific attributes
37
+
...componentSpecificAttributes
38
+
}
39
+
```
40
+
41
+
### component (required)
42
+
43
+
*string*
44
+
45
+
`component` is a string value representing used component. Available options depends on the component mapper. Data Driven Forms automatically checks if the component is available, if not, it shows an error message.
46
+
47
+
---
48
+
49
+
### name (required)
50
+
51
+
*string*
52
+
53
+
`name` represents the variable the form value is stored in. You can use [dot notatiton](https://final-form.org/docs/final-form/field-names) to create nested objects.
54
+
55
+
```jsx
56
+
{
57
+
...,
58
+
name:'person.name'
59
+
}
60
+
```
61
+
62
+
will be transformed to
63
+
64
+
```jsx
65
+
{
66
+
person: {
67
+
name:'value'
68
+
}
69
+
}
70
+
```
71
+
72
+
---
73
+
74
+
### actions
75
+
76
+
*object*
77
+
78
+
An object that allows to map other properties to globally defined actions. For example, a select has lazy loaded option and with this you can define parameters for the function and keep them in a string format. Read more [here](/mappers/action-mapper).
79
+
80
+
---
81
+
82
+
### clearedValue
83
+
84
+
*any*
85
+
86
+
A value that will be used if the field is cleared. Read more [here](/schema/cleared-value).
87
+
88
+
---
89
+
90
+
### clearOnUnmount
91
+
92
+
*bool*
93
+
94
+
When `true`, the value will be cleared after the component is unmounted. Read more [here](/schema/clear-on-unmount)
95
+
96
+
---
97
+
98
+
### condition
99
+
100
+
*object* | *array*
101
+
102
+
`condition` allows to hide/show field when a [condition](/schema/condition-schema) is fulfilled.
103
+
104
+
Example:
105
+
106
+
```jsx
107
+
{
108
+
...,
109
+
condition: {
110
+
when:'first-name',
111
+
is:'Douglas'
112
+
}
113
+
}
114
+
```
115
+
116
+
A field with this configuration will be shown only if the first name is Douglas.
117
+
118
+
There are multiple condition types: [and](/schema/and), [or](/schema/or), [not](/schema/not), [sequence](/schema/condition-sequence) that can be [nested](/schema/condition-nesting).
119
+
120
+
And there are multiple matchers: [is](/schema/is), [isEmpty](/schema/is-empty), [isNotTempy](/schema/is-not-empty), [pattern](/schema/pattern). Some of these matchers can be inverted by using [notMatch](/schema/not-match).
121
+
122
+
There are also two actions that can be binded to conditions: [set](/schema/condition-set) and [visible](/schema/condition-visible).
123
+
124
+
---
125
+
126
+
### dataType
127
+
128
+
one of strings: *integer | float | number | boolean | string*
129
+
130
+
Data type sets the type the value will be converted to. Read more [here](/schema/data-types).
131
+
132
+
---
133
+
134
+
### hideField
135
+
136
+
*bool*
137
+
138
+
When `true`, then this will be hidden by CSS. The value will be still registered and submitted.
139
+
140
+
---
141
+
142
+
### initializeOnMount
143
+
144
+
*bool*
145
+
146
+
When `true`, the value will be re-initialized every time the component is mounted. Read more [here](/schema/initialize-on-mount).
147
+
148
+
---
149
+
150
+
### initialValue
151
+
152
+
*any*
153
+
154
+
Sets an initial value of the field. Read more [here](https://final-form.org/docs/react-final-form/types/FieldProps#initialvalue).
155
+
156
+
---
157
+
158
+
### validate
159
+
160
+
*array*
161
+
162
+
`validate` array sets up validation of the field. It is an array of objects/functions:
163
+
164
+
**object**
165
+
166
+
```jsx
167
+
{
168
+
...,
169
+
validate: [{type:'required'}]
170
+
}
171
+
```
172
+
173
+
Type is one of our provided validators: [required](/schema/required-validator), [length](/schema/length-validator), [URL](/schema/url-validator), [pattern](/schema/pattern-validator), [number value](/schema/number-value-validator).
174
+
175
+
Or you can implement your own via creating a [validator mapper](/mappers/validator-mapper).
176
+
177
+
**function**
178
+
179
+
You can pass a [custom function](/schema/custom-validator):
180
+
181
+
```jsx
182
+
{
183
+
...,
184
+
validate: [function]
20
185
}
21
186
```
22
187
23
-
## Validate
188
+
This also supports using [async functions](/schema/async-validator).
24
189
25
-
You need to provide a `validate` array in the schema to add validation to your form fields.
190
+
---
26
191
27
-
A item of the validate array can be:
28
-
* a) object containing type and other specific configuration attributes (see validators description)
29
-
* b) function
192
+
### componentSpecificAttributes
193
+
194
+
Each component defines its required and optional props. Read more [here](/mappers/component-api).
195
+
196
+
```jsx
197
+
{
198
+
component:'text-field',
199
+
name:'password',
200
+
label:'Enter password', // component defined prop
201
+
type:'password', // component defined prop
202
+
helperText:'Please enter your password'// component defined prop
0 commit comments