Skip to content

Commit 3cb85e3

Browse files
committed
doc: revise schema/fieldProperties
1 parent 0c1fbd8 commit 3cb85e3

File tree

7 files changed

+118
-51
lines changed

7 files changed

+118
-51
lines changed
Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,38 @@
1-
**What are input and meta?**
1+
**What are meta and input?**
22

3-
**Input**
3+
<br/>
44

5-
Input is an object which contains field values and methods that change form state. See the selection of most important attributes:
5+
**meta**
66

7+
`meta` is an object which contains meta information about field with given name. There is a lot of information about every field.
8+
9+
[Here is the full list](https://final-form.org/docs/react-final-form/types/FieldRenderProps#metaactive) of commonly used `meta` information.
710
```jsx
811
{
9-
value: any, // any value of given form field. Its data type is based on field data type
10-
name: string, // unique name of form field. Value will be accessible under this key in form state
11-
onBlur: (event) => void, // function that should be triggered on field blur event
12-
onChange: (value) => void, // function that changes value of field in formState. Should be called whenever you want to change value of field
13-
onFocus: (event) => void, // function that should be triggered on field focus event
12+
error: any, // whatever your validation function returns
13+
pristine: bool, // true if the current value is === to the initial value, false if the values are !==.
14+
dirty: bool, // opposite of pristine
15+
touched: bool, //true if this field has ever gained and lost focus. false otherwise. Useful for knowing when to display error messages.
16+
valid: bool //true if this field has no validation or submission errors. false otherwise.
1417
}
1518
```
1619

17-
Every user interaction that updates field value in form state should also call `input.onChange` with correct value.
20+
<br/>
21+
22+
**input**
23+
24+
`input` is an object, which contains field values and methods that change form state.
1825

19-
**Meta**
26+
See the selection of the most important attributes:
2027

21-
Meta is a object which contains meta information about field with given name. There is a lot of information about every field.
22-
[Full list is here](https://final-form.org/docs/react-final-form/types/FieldRenderProps#metaactive). These are commonly used meta informations
2328
```jsx
2429
{
25-
error: any, // whatever your validation function returns
26-
pristine: bool, // true if the current value is === to the initial value, false if the values are !==.
27-
dirty: bool, // opposite of pristine
28-
touched: bool, //true if this field has ever gained and lost focus. false otherwise. Useful for knowing when to display error messages.
29-
valid: bool //true if this field has no validation or submission errors. false otherwise.
30+
value: any, // any value of given form field. Its data type is based on field data type
31+
name: string, // unique name of form field. Value will be accessible under this key in form state
32+
onBlur: (event) => void, // function that should be triggered on field blur event
33+
onChange: (value) => void, // function that changes value of field in formState. Should be called whenever you want to change value of field
34+
onFocus: (event) => void, // function that should be triggered on field focus event
3035
}
31-
```
36+
```
37+
38+
Every user interaction that updates field value in form state should also call `input.onChange` with correct value.

packages/react-renderer-demo/src/pages/schema/clear-on-unmount.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,25 @@ import CodeExample from '@docs/code-example';
33

44
<DocPage>
55

6-
# Clear on unmount
6+
# clearOnUnmount
77

88
*boolean*
99

10-
When using dynamic forms where more fields share the same name, the value is preserved when a user switches the field. You can disable this behavior by setting
11-
`clearOnUnmount` option in the renderer component or in the schema of the field. The option in the schema has always higher priority. (When
12-
`clearOnUnmount` is set in the renderer and the field has it this attribute set to `false`, the field value will not be cleared.)
10+
When using dynamic forms where more fields share the same name, the value is preserved when a user switches the field.
11+
12+
You can disable this behavior by setting `clearOnUnmount` option in the renderer component, or in the schema of the field.
13+
14+
The option in the schema has always higher priority. (When `clearOnUnmount` is set to `ture` in the renderer, and this attribute is set to `false` in the schema of the the field, the field value will not be cleared.)
15+
16+
<br/>
1317

1418
## Examples
1519

1620
### Form example
1721

1822
<CodeExample source="components/clear-on-unmount" mode="preview" />
1923

24+
<br/>
2025

2126
### Form level configuration
2227

@@ -30,6 +35,8 @@ When using dynamic forms where more fields share the same name, the value is pre
3035
/>
3136
```
3237

38+
<br/>
39+
3340
### Field level configuration
3441

3542
```jsx

packages/react-renderer-demo/src/pages/schema/cleared-value.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ import DocPage from '@docs/doc-page';
33

44
<DocPage>
55

6-
# Cleared value
6+
# clearedValue
77

88
*any*
99

10-
The value to send upon a submit if the field is empty. This wildcard value can be used to distinguish between an untouched field and a cleared one (it will be only used when field has initialValue). For example if you have a form that edits an entity and you would like to clear an attribute. Some APIs require the value to be set to null to register the change.
10+
`clearedValue` is the value to send upon a submit if the field is empty.
11+
12+
This wildcard value can be used to distinguish between an untouched field and a cleared one (it will be only used when field has `initialValue`).
13+
14+
For example, if you have a form that edits an entity and you would like to clear an attribute of the form, some APIs require the `clearedValue` to be set to null to register the change.
1115

1216

1317
<CodeExample source="components/cleared-value" mode="preview" />

packages/react-renderer-demo/src/pages/schema/constants.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import DocPage from '@docs/doc-page';
44

55
# Constants
66

7-
Data Driven Forms provides two constants files to keep consistency across all projects and prevent typos.
7+
**Data Driven Forms** provides two constant files to keep consistency across all projects and prevent typos.
8+
9+
<br/>
810

911
## componentTypes
1012

11-
Strings values used in `component` field attributes.
13+
`componentTypes` are string values used in `component` field attributes.
1214

1315
```jsx
1416
import { componentTypes } from '@data-driven-forms/react-form-renderer';
@@ -48,9 +50,11 @@ Usage:
4850
}
4951
```
5052

53+
<br/>
54+
5155
## validatorTypes
5256

53-
Strings values used in `validate` [type attribute](/schema/introduction#validate).
57+
`validatorTypes` are string values used in `validate` [type attribute](/schema/introduction#validate).
5458

5559
```jsx
5660
import { validatorTypes } from '@data-driven-forms/react-form-renderer';

packages/react-renderer-demo/src/pages/schema/data-types.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ import DocPage from '@docs/doc-page';
33

44
<DocPage>
55

6-
# Data Types
6+
# dataType
77

88
*string*
99

10-
You can specify a type of a component by providing `dataType`, which will automatically validates the component value.
11-
Because almost everything in HTML inputs is outputed as a string, adding the `dataType` props will also cast the value to given type.
10+
You can specify the type of a component by providing `dataType`, which will automatically validates the component value.
11+
12+
Because almost everything in HTML inputs is outputed as a string, adding the `dataType` props will also cast the value to the given type.
13+
14+
<br/>
1215

1316
## Example
1417

@@ -21,6 +24,8 @@ Because almost everything in HTML inputs is outputed as a string, adding the `da
2124
}
2225
```
2326

27+
<br/>
28+
2429
## Available dataTypes
2530

2631
```jsx

packages/react-renderer-demo/src/pages/schema/initialize-on-mount.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@ import CodeExample from '@docs/code-example';
33

44
<DocPage>
55

6-
# Initialize On Mount
6+
# initializeOnMount
77

88
*boolean*
99

10-
Data Driven Forms provides a way how you can easily initialized a field when the field is mounted (re-mounted).
10+
**Data Driven Forms** provides a way how you can easily initialize a field when the field is mounted (re-mounted).
1111

1212
Just pass a `initializeOnMount` prop and set it to `true`.
1313

14-
The field will use the `initialValue` set in the schema ([initialValue](/schema/introduction#initialvalue)).
14+
The field will use the `initialValue` set in the schema ([`initialValue`](/schema/introduction#initialvalue)).
1515

1616
`initialValue` has higher priority than a value from `initialValues`.
1717

18+
<br/>
19+
1820
## Example
1921

2022

@@ -27,14 +29,24 @@ The field will use the `initialValue` set in the schema ([initialValue](/schema/
2729
}
2830
```
2931

32+
<br/>
33+
3034
## When to use it?
3135

32-
This feature comes handy if you need change a value when an user traverses a form, which shows and hides fields, and the value is not set by the user. Very useful case is used it wizard forms, where you can set different value for the same input according the way the user went in the wizard form by using this option combined with [hideField](/schema/introduction#hidefield) prop.
36+
If you need to change a value when a user traverses a form, which shows and hides fields, and the value is not set by the user, this feature comes handy.
37+
38+
A very useful case:
39+
40+
> When you use `initializeOnMount` in wizard forms, you can set different values to one input component which leads users to different ways as the following example component.
41+
42+
> To achieve this implementation, you may need to use `initializeOnMount` combined with [`hideField`](/schema/introduction#hidefield) property.
3343
3444
<CodeExample source="components/initialize-mount" mode="preview" />
3545

46+
<br/>
47+
3648
## Clear the value
3749

38-
If you need clear the value after unmounting, you can do it by using [clearOnUnmount](/schema/clear-on-unmount).
50+
If you need to clear the value after unmounting, you can do it by using [clearOnUnmount](/schema/clear-on-unmount).
3951

4052
</DocPage>

packages/react-renderer-demo/src/pages/schema/resolve-props.md

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@ import CodeExample from '@docs/code-example';
44

55
<DocPage>
66

7-
# Resolve props
7+
# resolveProps
88

99
*function (props, {meta, input}, formOptions) => props*
1010

11-
**Only applicable for fields connected to the form state.**
1211

13-
A function allowing to compute field properties from the current state of the field.
12+
**resolveProps is only applicable for fields that connected to the form state.**
1413

15-
## Schema
14+
The function of resolveProps can compute field properties from the current state of the field.
15+
16+
<br/>
17+
18+
## Example
1619

1720
```jsx
1821
const schema = {
@@ -23,33 +26,50 @@ const schema = {
2326
}
2427
```
2528

29+
<br/>
30+
2631
## Arguments
2732

28-
### Props
33+
### props
2934

30-
All field props passed in the schema.
35+
`props` are all field properties passed in the schema.
3136

32-
### Meta and input
37+
<br/>
3338

39+
### meta and input
40+
41+
<br/>
3442
<InputMeta />
3543

36-
### FormOptions
44+
<br/>
45+
46+
### formOptions
47+
48+
`formOptions` is an object containing access to the form state.
49+
50+
[Read more.](/hooks/use-form-api)
3751

38-
Object containing access to the form state. Read more [here](/hooks/use-form-api).
52+
<br/>
3953

4054
## Rules
4155

42-
I. `resolveProps` cannot return `actions`. You can access `actions`'s code in the `resolveProps` prop if you need it.
56+
Here are some rules about using `resolveProps`:
57+
58+
I. `resolveProps` cannot return `actions`. You can access `actions`'s code in the `resolveProps` props if you need it.
4359

4460
II. Do not use `async` functions to get the props.
4561

46-
III. Do not trigger any side effects, as it could introduce bugs.
62+
III. Do not trigger any side effects, as it may introduce bugs.
63+
64+
IV. `resolveProps` are merged together with the following priority:
4765

48-
IV. `resolveProps` are merged together with following priority: `actions.resolveProps` (highest) > `field.resolveProps` > `mapper.resolveProps` (lowest)
66+
`actions.resolveProps` (highest) > `field.resolveProps` > `mapper.resolveProps` (lowest)
67+
68+
<br/>
4969

5070
## Global resolveProps
5171

52-
You can modify behavior for all components of the same type in your `componentMapper` via [global component props](/mappers/global-component-props).
72+
You can modify the behavior for all components of the same type in your `componentMapper` via [global component props](/mappers/global-component-props).
5373

5474
```jsx
5575
const componentMapper = {
@@ -60,13 +80,21 @@ const componentMapper = {
6080
}
6181
```
6282

63-
## Change props according to state of other components
83+
<br/>
84+
85+
## Change props according to the state of other components
6486

65-
You can get states of all other fields in the form via functions from `formOptions`. Don't forget to set the right [subscription](/components/renderer#subscription) to trigger `resolveProps` functions from changing other fields.
87+
You can get states of all the other fields in the form via functions from `formOptions`.
88+
89+
Don't forget to set the right [subscription](/components/renderer#subscription) to trigger `resolveProps` functions from the other changing fields.
90+
91+
<br/>
6692

6793
## Example
6894

69-
Following example shows how can be a behavior of components changed using `resolveProps`. In this example, the component will have different color and helper text after it is validated.
95+
The following example shows how `resolveProps` changes a behavior of components .
96+
97+
In this example, after the component is validated, it will have different colors and helper texts.
7098

7199
<CodeExample mode="preview" source="components/resolve-props" />
72100

0 commit comments

Comments
 (0)