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
Copy file name to clipboardExpand all lines: articles/ArrayForm.md
+11-9Lines changed: 11 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,5 @@
1
+
# ArrayForm
2
+
1
3
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)).
2
4
3
5
## Props
@@ -20,18 +22,18 @@ A function that renders the array.
20
22
21
23
The render function provides an object parameter, containing the following fields:
22
24
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.
26
28
27
29
**The object also contains helper functions to quickly manipulate the array field:**
28
30
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.
34
36
35
37
## Usage
36
38
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).
Copy file name to clipboardExpand all lines: articles/ChildForm.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,5 @@
1
+
# ChildForm
2
+
1
3
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).
2
4
3
5
## Props
@@ -22,4 +24,4 @@ A function that renders, and creates inputs for the child form, which is passed
22
24
23
25
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.
24
26
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 `{}`).
Copy file name to clipboardExpand all lines: articles/FormInput.md
+34-24Lines changed: 34 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,14 @@
1
+
# `<FormInput />`
2
+
1
3
A stateful, type-checked form `input` element.
2
4
3
5
The input transforms its value based on the `type` prop, which **currently supports the following input types**:
4
6
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`
10
12
11
13
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.
12
14
@@ -82,64 +84,72 @@ Checkboxes behave like a boolean field by default, but when given a value, it be
82
84
### Submit
83
85
84
86
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
+
```
91
94
92
95
## Props
93
96
94
97
#### `form`**(required)**
98
+
95
99
The form or child form that contains the field to bind to this input.
96
100
97
-
***
101
+
---
98
102
99
103
#### `name`**(required)**
104
+
100
105
The name of the field in the form that will be bound to this input.
101
106
102
-
***
107
+
---
103
108
104
109
#### `errorClassName` and `errorStyle`
110
+
105
111
The className and/or style to set when there is an error on thisfield. Default className is `typed-form-error`.
106
112
107
-
***
113
+
---
108
114
109
115
#### `dirtyClassName` and `dirtyStyle`
116
+
110
117
The className and/or style to set when this field has been modified. Default className is `typed-form-dirty`.
111
118
112
-
***
119
+
---
113
120
114
121
#### `disableOnSubmitting`
122
+
115
123
Disable this input on submit? Default is `true`.
116
124
117
-
***
125
+
---
118
126
119
127
#### `dateAsNumber` (only type="date")
128
+
120
129
Serialize this fields value as a timestamp instead of a Date object.
121
130
122
-
***
131
+
---
123
132
124
133
#### `hideWhenNull`
125
134
126
135
Setthis prop if you want to hide this input when its field value is `null/undefined`. Default is `false`.
127
136
128
-
***
137
+
---
129
138
130
139
#### `setNullOnUncheck` and `setUndefinedOnUncheck` (only type="checkbox")
140
+
131
141
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).
132
142
133
143
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.
134
144
135
-
***
145
+
---
136
146
137
147
#### `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.
141
148
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.
143
152
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
+
---
145
154
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).
Copy file name to clipboardExpand all lines: articles/FormState.md
+25-17Lines changed: 25 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,25 +1,31 @@
1
+
# `FormState`
2
+
1
3
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.
2
4
3
5
This class provides a lot of useful functions to manipulate form values and state.
4
6
5
7
## Properties
6
8
7
9
#### `values`**(readonly)**
10
+
8
11
The values of the form. Can be set with `setValues()`.
9
12
10
13
---
11
14
12
15
#### `defaultValues`**(readonly)**
16
+
13
17
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()`.
14
18
15
19
---
16
20
17
21
#### `childMap`**(readonly)**
22
+
18
23
Each child form bound registers itself in this object. It maps field names to `ChildFormState` instances.
19
24
20
25
---
21
26
22
27
#### `dirtyMap`**(readonly)**
28
+
23
29
Maps field names to dirty values. A field is dirty when its value is not equal anymore to its default value.
24
30
25
31
---
@@ -66,29 +72,29 @@ The form's validator.
66
72
67
73
Sets a field value or default value.
68
74
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.
-`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.
-`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.**
0 commit comments