Skip to content

Commit 95ecbae

Browse files
committed
Minor improvements to form reducers copy
1 parent df9c721 commit 95ecbae

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/components_guide_web/templates/react_typescript/form-reducers.html.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,23 @@ Fortunately the browser has two features to help us out: `FormData` and event de
88

99
## Thinking of validation as a linear process
1010

11-
We can think of validation as mapping from events to errors.
11+
We can think of validation as mapping from _events_ to _errors_.
1212

1313
We have two events: `blur` and `submit`.
1414

15-
When a field is blurred, we validate whether its value is valid or not.
15+
When a field is blurred, we validate whether its value is valid or not. This produces either one or no error.
1616

17-
When a whole form is submitted, we validate **all** of its fields at once.
17+
When a whole form is submitted, we validate **all** of its fields at once. This produces zero or more errors.
1818

1919
It would be great to write the same code to validate either a single field (when it is blurred) or a whole bunch of fields (when their form is submitted).
2020

2121
If we were to sketch out the steps it would look like:
2222

2323
1. Get the field(s) matching this event.
24-
2. Get the values from the fields.
24+
2. Get the values from the field(s).
2525
3. Validate each value.
2626
4. Store a key-value map for each error, with the key identifying the field, and the value holding the error message.
27+
5. Render out each field, with its error alongside.
2728

2829
So how do we do each of these steps?
2930

0 commit comments

Comments
 (0)