Skip to content

Commit 289ff28

Browse files
committed
Add titles to articles
1 parent dab8481 commit 289ff28

18 files changed

+222
-141
lines changed

articles/ArrayForm.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# ArrayForm
2+
13
A component that provides array manipulation functions and optimizations. This is a wrapper around [`useArrayForm`](https://github.com/CodeStix/typed-react-form/wiki/useArrayForm). The only difference is that this component does not render its content when the array is null/undefined ([is togglable](https://github.com/CodeStix/typed-react-form/wiki/Toggling-a-field)).
24

35
## Props
@@ -20,18 +22,18 @@ A function that renders the array.
2022

2123
The render function provides an object parameter, containing the following fields:
2224

23-
- `form`: The child form associated with this array. Pass this to this child forms and input elements.
24-
- `values`: The array, you should `{map((e) => ...)}` this.
25-
- `setValues(values)`: A function to update all the array values at once.
25+
- `form`: The child form associated with this array. Pass this to this child forms and input elements.
26+
- `values`: The array, you should `{map((e) => ...)}` this.
27+
- `setValues(values)`: A function to update all the array values at once.
2628

2729
**The object also contains helper functions to quickly manipulate the array field:**
2830

29-
- `remove(index)`: Function that removes a specific item at index in the array.
30-
- `clear()`: Function that clears the array.
31-
- `move(from, to)`: Function that moves an item in the array
32-
- `swap(index, newIndex)`: Function that swaps 2 items in the array.
33-
- `append(value)`: Function that appends an item to the end of the array.
31+
- `remove(index)`: Function that removes a specific item at index in the array.
32+
- `clear()`: Function that clears the array.
33+
- `move(from, to)`: Function that moves an item in the array
34+
- `swap(index, newIndex)`: Function that swaps 2 items in the array.
35+
- `append(value)`: Function that appends an item to the end of the array.
3436

3537
## Usage
3638

37-
See [Array fields](https://github.com/CodeStix/typed-react-form/wiki/Array-fields).
39+
See [Array fields](https://github.com/CodeStix/typed-react-form/wiki/Array-fields).

articles/ChildForm.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# ChildForm
2+
13
Use the `ChildForm` component if you want to make fields inside an object field available to inputs. This is a wrapper around [`useChildForm`](https://github.com/CodeStix/typed-react-form/wiki/useChildForm).
24

35
## Props
@@ -22,4 +24,4 @@ A function that renders, and creates inputs for the child form, which is passed
2224

2325
You can also use this component on array fields (index as name), but [`ArrayForm`](https://github.com/CodeStix/typed-react-form/wiki/ArrayForm) or [`useArrayForm`](https://github.com/CodeStix/typed-react-form/wiki/useArrayForm) is preferred when you want to create [dynamic array fields](https://github.com/CodeStix/typed-react-form/wiki/Array-fields). It provides useful array manipulation functions and optimizations.
2426

25-
This component does not render its content when the form is empty (happens when its parent field has been assigned `null`, `undefined` or `{}`).
27+
This component does not render its content when the form is empty (happens when its parent field has been assigned `null`, `undefined` or `{}`).

articles/FormError.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
A very simple field error component.
1+
# `<FormError />`
2+
3+
A very simple field error component.
24

35
```jsx
46
const form = useForm(
@@ -29,7 +31,7 @@ function CustomFormError<T>(props: { form: FormState<T>; name: keyof T }) {
2931
const { error } = useListener(props.form, props.name);
3032

3133
// Render nothing when no error
32-
if (!error)
34+
if (!error)
3335
return null;
3436

3537
// Render a styled span on error.
@@ -41,4 +43,3 @@ function CustomFormError<T>(props: { form: FormState<T>; name: keyof T }) {
4143
```
4244

4345
You can also create custom input components, look [here](https://github.com/CodeStix/typed-react-form/wiki/Custom-inputs).
44-

articles/FormInput.md

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
# `<FormInput />`
2+
13
A stateful, type-checked form `input` element.
24

35
The input transforms its value based on the `type` prop, which **currently supports the following input types**:
46

5-
- `text`
6-
- `number`
7-
- `date` (Date and number timestamp)
8-
- `checkbox`
9-
- `radio`
7+
- `text`
8+
- `number`
9+
- `date` (Date and number timestamp)
10+
- `checkbox`
11+
- `radio`
1012

1113
It is allowed to use multiple inputs on the same field, all of them will be synchronized. These inputs are given a `className` when errored (`typed-form-error`) or modified (`typed-form-dirty`) by default.
1214

@@ -82,64 +84,72 @@ Checkboxes behave like a boolean field by default, but when given a value, it be
8284
### Submit
8385

8486
You **cannot** use FormInput to create a submit button (type="submit"). Use one of the following alternatives:
85-
- ```jsx
86-
<input type="submit" value="Click here to submit"/>
87-
```
88-
- ```jsx
89-
<button>Click here to submit</button>
90-
```
87+
88+
- ```jsx
89+
<input type="submit" value="Click here to submit" />
90+
```
91+
- ```jsx
92+
<button>Click here to submit</button>
93+
```
9194

9295
## Props
9396

9497
#### `form` **(required)**
98+
9599
The form or child form that contains the field to bind to this input.
96100

97-
***
101+
---
98102

99103
#### `name` **(required)**
104+
100105
The name of the field in the form that will be bound to this input.
101106

102-
***
107+
---
103108

104109
#### `errorClassName` and `errorStyle`
110+
105111
The className and/or style to set when there is an error on this field. Default className is `typed-form-error`.
106112

107-
***
113+
---
108114

109115
#### `dirtyClassName` and `dirtyStyle`
116+
110117
The className and/or style to set when this field has been modified. Default className is `typed-form-dirty`.
111118

112-
***
119+
---
113120

114121
#### `disableOnSubmitting`
122+
115123
Disable this input on submit? Default is `true`.
116124

117-
***
125+
---
118126

119127
#### `dateAsNumber` (only type="date")
128+
120129
Serialize this fields value as a timestamp instead of a Date object.
121130

122-
***
131+
---
123132

124133
#### `hideWhenNull`
125134

126135
Set this prop if you want to hide this input when its field value is `null/undefined`. Default is `false`.
127136

128-
***
137+
---
129138

130139
#### `setNullOnUncheck` and `setUndefinedOnUncheck` (only type="checkbox")
140+
131141
When using one of these props, the checkbox will set null/undefined on the field when unchecked. This prop is only valid for checkboxes. (Can mimic the same behaviour with radio buttons using value props).
132142

133143
Make sure you pass along a `value` too, this is the value that will be set when it gets checked again. Not doing so, will cause a console warning.
134144

135-
***
145+
---
136146

137147
#### `value` (only type="radio" or type="checkbox")
138-
- The value of the radio button when using multi-value fields.
139-
- The value of the checkbox when using primitive arrays.
140-
- The on-checked value of the checkbox when using the `setNullOnUncheck/setUndefinedOnUncheck` prop.
141148

142-
***
149+
- The value of the radio button when using multi-value fields.
150+
- The value of the checkbox when using primitive arrays.
151+
- The on-checked value of the checkbox when using the `setNullOnUncheck/setUndefinedOnUncheck` prop.
143152

144-
All of the input components are wrappers and abstractions around the [`useListener`](https://github.com/CodeStix/typed-react-form/wiki/useListener) hook. Using this hook, you can create your own [custom inputs](https://github.com/CodeStix/typed-react-form/wiki/Custom-inputs).
153+
---
145154

155+
All of the input components are wrappers and abstractions around the [`useListener`](https://github.com/CodeStix/typed-react-form/wiki/useListener) hook. Using this hook, you can create your own [custom inputs](https://github.com/CodeStix/typed-react-form/wiki/Custom-inputs).

articles/FormSelect.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# `<FormSelect />`
2+
13
A stateful, type-checked form `select` element.
24

35
These inputs are given a `className` when errored (`typed-form-error`) or modified (`typed-form-dirty`) by default.
@@ -27,30 +29,35 @@ const form = useForm({
2729
## Props
2830

2931
#### `form` (required)
32+
3033
The form or child form that contains the field to bind to this select input.
3134

32-
***
35+
---
3336

3437
#### `name` (required)
38+
3539
The name of the field in the form that will be bound to this select input.
3640

37-
***
41+
---
3842

3943
#### `errorClassName` and `errorStyle`
44+
4045
The className and/or style to set when there is an error on this field. Default className is `typed-form-error`.
4146

42-
***
47+
---
4348

4449
#### `dirtyClassName` and `dirtyStyle`
50+
4551
The className and/or style to set when this field has been modified. Default className is `typed-form-dirty`.
4652

47-
***
53+
---
4854

4955
#### `disableOnSubmitting`
56+
5057
Disable this select input on submit? Default is `true`.
5158

59+
---
5260

53-
***
5461
#### `hideWhenNull`
5562

5663
Set this prop if you want to hide this input when its field value is `null/undefined`. Default is `false`.

articles/FormState.md

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
1+
# `FormState`
2+
13
The `FormState` class contains all the state of a form. This includes values, default values, errors, dirty flags and form state. You should always use the `useForm` or `useChildForm` hooks to create an instance of this class.
24

35
This class provides a lot of useful functions to manipulate form values and state.
46

57
## Properties
68

79
#### `values` **(readonly)**
10+
811
The values of the form. Can be set with `setValues()`.
912

1013
---
1114

1215
#### `defaultValues` **(readonly)**
16+
1317
The default values of the form. Input elements do not change this. This gets used to reset the form and to calculate dirty flags. Can be set with `setDefaultValues()`.
1418

1519
---
1620

1721
#### `childMap` **(readonly)**
22+
1823
Each child form bound registers itself in this object. It maps field names to `ChildFormState` instances.
1924

2025
---
2126

2227
#### `dirtyMap` **(readonly)**
28+
2329
Maps field names to dirty values. A field is dirty when its value is not equal anymore to its default value.
2430

2531
---
@@ -66,29 +72,29 @@ The form's validator.
6672

6773
Sets a field value or default value.
6874

69-
- `name` **(required)**: The field name to set a value for.
70-
- `value` **(required)**: The new value for the field.
71-
- `validate` **(optional)**: Validate? When defined, overrides `validateOnChange`.
72-
- `isDefault` **(optional, false)**: When true, updates the default value instead of the normal value.
75+
- `name` **(required)**: The field name to set a value for.
76+
- `value` **(required)**: The new value for the field.
77+
- `validate` **(optional)**: Validate? When defined, overrides `validateOnChange`.
78+
- `isDefault` **(optional, false)**: When true, updates the default value instead of the normal value.
7379

7480
---
7581

7682
#### `setValues(values, validate = true, isDefault = false, notifyChild = true, notifyParent = true)`
7783

78-
Sets values *OR* default values for a form.
84+
Sets values _OR_ default values for a form.
7985

80-
- `values` **(required)**: The new values/default values to set on this form.
81-
- `validate` **(optional)**: Validate? When defined, overrides `validateOnChange`.
82-
- `isDefault` **(optional, false)**: When true, updates the default values instead of the normal values. Only updates one or the other, to set both at the same time, use `setDefaultValues()` or 2 function calls.
86+
- `values` **(required)**: The new values/default values to set on this form.
87+
- `validate` **(optional)**: Validate? When defined, overrides `validateOnChange`.
88+
- `isDefault` **(optional, false)**: When true, updates the default values instead of the normal values. Only updates one or the other, to set both at the same time, use `setDefaultValues()` or 2 function calls.
8389

8490
---
8591

8692
#### `setDefaultValues(values, validate = true, notifyChild = true, notifyParent = true)`
8793

88-
Set both values *AND* default values for a form. If you only want to set default values, use `setValues(...,...,true)`.
94+
Set both values _AND_ default values for a form. If you only want to set default values, use `setValues(...,...,true)`.
8995

90-
- `values` **(required)**: The new values to set on this form.
91-
- `validate` **(optional)**: Validate? When defined, overrides `validateOnChange`.
96+
- `values` **(required)**: The new values to set on this form.
97+
- `validate` **(optional)**: Validate? When defined, overrides `validateOnChange`.
9298

9399
---
94100

@@ -102,36 +108,38 @@ Force validation on this form. Required when `validateOnChange` is disabled. Tak
102108

103109
Set an error on a specific field in this form.
104110

105-
- `name` **(required)**: The field name to set an error on.
106-
- `error` **(required)**: The error to set.
111+
- `name` **(required)**: The field name to set an error on.
112+
- `error` **(required)**: The error to set.
107113

108114
---
109115

110116
#### `setErrors(errors, notifyChild = true, notifyParent = true)`
111117

112118
Set all the errors on this form and child forms.
113119

114-
- `errors` **(required)**: The new errors for this form. Use {} to clear errors. **The format of this error object must follow the same structure of the values object, but each value is replaced by its error.**
120+
- `errors` **(required)**: The new errors for this form. Use {} to clear errors. **The format of this error object must follow the same structure of the values object, but each value is replaced by its error.**
115121

116122
---
117123

118124
#### `resetAll(validate = true, notifyChild = true, notifyParent = true)`
125+
119126
Resets the values in this form to the default values. Causes validation.
120127

121128
---
122129

123130
#### `reset(name, validate = true, notifyChild = true, notifyParent = true)`
131+
124132
Reset a specific field in this form to its default value.
125133

126-
- `name` **(required)**: The field to reset to its default value.
134+
- `name` **(required)**: The field to reset to its default value.
127135

128136
---
129137

130138
#### `setState(newState)`
131139

132140
Updates the state of this form, this causes every input to rerender. This also updates the state in parent and child forms **by default**.
133141

134-
- `newState` **(required)**: The new form state.
142+
- `newState` **(required)**: The new form state.
135143

136144
---
137145

@@ -153,4 +161,4 @@ The parent form of this form. Which is a `FormState` or `ChildFormState` instanc
153161

154162
#### `name`
155163

156-
The name of this form, which is the name of the field in the parent form which this child form represents.
164+
The name of this form, which is the name of the field in the parent form which this child form represents.

0 commit comments

Comments
 (0)