envoc-form 4.0.1-9 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9443 -12
- package/es/AddressInput/AddressInput.d.ts +15 -5
- package/es/AddressInput/AddressInput.js +10 -0
- package/es/ConfirmBaseForm/ConfirmBaseForm.d.ts +14 -0
- package/es/ConfirmBaseForm/ConfirmBaseForm.js +6 -0
- package/es/ConfirmDeleteForm/ConfirmDeleteForm.d.ts +13 -0
- package/es/ConfirmDeleteForm/ConfirmDeleteForm.js +5 -0
- package/es/DatePicker/DatePickerGroup.d.ts +7 -2
- package/es/DatePicker/DatePickerGroup.js +18 -7
- package/es/DatePicker/StringDateOnlyPickerGroup.d.ts +6 -1
- package/es/DatePicker/StringDateOnlyPickerGroup.js +5 -0
- package/es/DatePicker/StringDatePickerGroup.d.ts +6 -1
- package/es/DatePicker/StringDatePickerGroup.js +5 -0
- package/es/DateTimePicker/DateTimePickerGroup.d.ts +13 -0
- package/es/DateTimePicker/DateTimePickerGroup.js +87 -0
- package/es/DateTimePicker/DateTimePickerHelper.d.ts +3 -0
- package/es/DateTimePicker/DateTimePickerHelper.js +1 -0
- package/es/DateTimePicker/StringDateTimePickerGroup.d.ts +10 -0
- package/es/DateTimePicker/StringDateTimePickerGroup.js +53 -0
- package/es/Field/Field.d.ts +9 -3
- package/es/Field/Field.js +9 -4
- package/es/Field/FieldErrorScrollTarget.d.ts +1 -0
- package/es/Field/FieldErrorScrollTarget.js +1 -0
- package/es/Field/StandAloneInput.d.ts +4 -0
- package/es/Field/StandAloneInput.js +1 -0
- package/es/Field/useStandardField.d.ts +6 -0
- package/es/Field/useStandardField.js +8 -9
- package/es/FieldArray/FieldArray.d.ts +11 -2
- package/es/FieldArray/FieldArray.js +7 -2
- package/es/File/FileGroup.d.ts +3 -1
- package/es/File/FileGroup.js +4 -3
- package/es/File/FileList.d.ts +2 -2
- package/es/Form/FocusError.d.ts +2 -0
- package/es/Form/FocusError.js +1 -0
- package/es/Form/Form.d.ts +6 -0
- package/es/Form/Form.js +1 -0
- package/es/Form/FormBasedPreventNavigation.d.ts +3 -1
- package/es/Form/FormBasedPreventNavigation.js +12 -45
- package/es/Form/LegacyFormBasedPreventNavigation.d.ts +17 -0
- package/es/Form/LegacyFormBasedPreventNavigation.js +69 -0
- package/es/Form/NewFormBasedPreventNavigation.d.ts +14 -0
- package/es/Form/NewFormBasedPreventNavigation.js +39 -0
- package/es/Form/ServerErrorContext.d.ts +1 -0
- package/es/Form/ServerErrorContext.js +1 -0
- package/es/FormActions.d.ts +6 -0
- package/es/FormActions.js +1 -0
- package/es/FormDefaults.d.ts +1 -0
- package/es/FormDefaults.js +1 -0
- package/es/Group.d.ts +7 -4
- package/es/Group.js +4 -3
- package/es/Input/IconInputGroup.d.ts +4 -1
- package/es/Input/IconInputGroup.js +3 -1
- package/es/Input/InputGroup.d.ts +4 -4
- package/es/Input/InputGroup.js +4 -4
- package/es/Input/MoneyInputGroup.d.ts +3 -1
- package/es/Input/MoneyInputGroup.js +1 -0
- package/es/Input/NumberInputGroup.d.ts +3 -1
- package/es/Input/NumberInputGroup.js +1 -0
- package/es/Input/PhoneNumberInputGroup.d.ts +10 -0
- package/es/Input/PhoneNumberInputGroup.js +47 -0
- package/es/Input/StringInputGroup.d.ts +2 -1
- package/es/Input/StringInputGroup.js +3 -1
- package/es/Normalization/normalizers.d.ts +4 -2
- package/es/Normalization/normalizers.js +2 -0
- package/es/Select/BooleanSelectGroup.d.ts +2 -1
- package/es/Select/BooleanSelectGroup.js +1 -0
- package/es/Select/NumberSelectGroup.d.ts +4 -2
- package/es/Select/NumberSelectGroup.js +2 -0
- package/es/Select/SelectGroup.d.ts +8 -2
- package/es/Select/SelectGroup.js +5 -4
- package/es/Select/StringSelectGroup.d.ts +2 -0
- package/es/Select/StringSelectGroup.js +2 -0
- package/es/StandardFormActions.d.ts +5 -0
- package/es/StandardFormActions.js +1 -0
- package/es/SubmitFormButton.d.ts +4 -1
- package/es/SubmitFormButton.js +1 -0
- package/es/TextArea/TextAreaGroup.d.ts +2 -1
- package/es/TextArea/TextAreaGroup.js +5 -4
- package/es/Validation/validators.d.ts +11 -8
- package/es/Validation/validators.js +6 -2
- package/es/hooks/index.d.ts +2 -0
- package/es/hooks/index.js +2 -0
- package/es/hooks/useFormValue.d.ts +2 -0
- package/es/hooks/useFormValue.js +7 -0
- package/es/index.d.ts +10 -4
- package/es/index.js +4 -0
- package/es/setupTests.d.ts +1 -0
- package/es/setupTests.js +1 -0
- package/lib/AddressInput/AddressInput.d.ts +15 -5
- package/lib/AddressInput/AddressInput.js +10 -0
- package/lib/ConfirmBaseForm/ConfirmBaseForm.d.ts +14 -0
- package/lib/ConfirmBaseForm/ConfirmBaseForm.js +6 -0
- package/lib/ConfirmDeleteForm/ConfirmDeleteForm.d.ts +13 -0
- package/lib/ConfirmDeleteForm/ConfirmDeleteForm.js +5 -0
- package/lib/DatePicker/DatePickerGroup.d.ts +7 -2
- package/lib/DatePicker/DatePickerGroup.js +18 -7
- package/lib/DatePicker/StringDateOnlyPickerGroup.d.ts +6 -1
- package/lib/DatePicker/StringDateOnlyPickerGroup.js +5 -0
- package/lib/DatePicker/StringDatePickerGroup.d.ts +6 -1
- package/lib/DatePicker/StringDatePickerGroup.js +5 -0
- package/lib/DateTimePicker/DateTimePickerGroup.d.ts +13 -0
- package/lib/DateTimePicker/DateTimePickerGroup.js +93 -0
- package/lib/DateTimePicker/DateTimePickerHelper.d.ts +3 -0
- package/lib/DateTimePicker/DateTimePickerHelper.js +2 -0
- package/lib/DateTimePicker/StringDateTimePickerGroup.d.ts +10 -0
- package/lib/DateTimePicker/StringDateTimePickerGroup.js +59 -0
- package/lib/Field/Field.d.ts +9 -3
- package/lib/Field/Field.js +9 -4
- package/lib/Field/FieldErrorScrollTarget.d.ts +1 -0
- package/lib/Field/FieldErrorScrollTarget.js +1 -0
- package/lib/Field/StandAloneInput.d.ts +4 -0
- package/lib/Field/StandAloneInput.js +1 -0
- package/lib/Field/useStandardField.d.ts +6 -0
- package/lib/Field/useStandardField.js +8 -9
- package/lib/FieldArray/FieldArray.d.ts +11 -2
- package/lib/FieldArray/FieldArray.js +7 -2
- package/lib/File/FileGroup.d.ts +3 -1
- package/lib/File/FileGroup.js +4 -3
- package/lib/File/FileList.d.ts +2 -2
- package/lib/Form/FocusError.d.ts +2 -0
- package/lib/Form/FocusError.js +1 -0
- package/lib/Form/Form.d.ts +6 -0
- package/lib/Form/Form.js +1 -0
- package/lib/Form/FormBasedPreventNavigation.d.ts +3 -1
- package/lib/Form/FormBasedPreventNavigation.js +13 -43
- package/lib/Form/LegacyFormBasedPreventNavigation.d.ts +17 -0
- package/lib/Form/LegacyFormBasedPreventNavigation.js +72 -0
- package/lib/Form/NewFormBasedPreventNavigation.d.ts +14 -0
- package/lib/Form/NewFormBasedPreventNavigation.js +42 -0
- package/lib/Form/ServerErrorContext.d.ts +1 -0
- package/lib/Form/ServerErrorContext.js +1 -0
- package/lib/FormActions.d.ts +6 -0
- package/lib/FormActions.js +1 -0
- package/lib/FormDefaults.d.ts +1 -0
- package/lib/FormDefaults.js +1 -0
- package/lib/Group.d.ts +7 -4
- package/lib/Group.js +4 -3
- package/lib/Input/IconInputGroup.d.ts +4 -1
- package/lib/Input/IconInputGroup.js +3 -1
- package/lib/Input/InputGroup.d.ts +4 -4
- package/lib/Input/InputGroup.js +4 -4
- package/lib/Input/MoneyInputGroup.d.ts +3 -1
- package/lib/Input/MoneyInputGroup.js +1 -0
- package/lib/Input/NumberInputGroup.d.ts +3 -1
- package/lib/Input/NumberInputGroup.js +1 -0
- package/lib/Input/PhoneNumberInputGroup.d.ts +10 -0
- package/lib/Input/PhoneNumberInputGroup.js +52 -0
- package/lib/Input/StringInputGroup.d.ts +2 -1
- package/lib/Input/StringInputGroup.js +3 -1
- package/lib/Normalization/normalizers.d.ts +4 -2
- package/lib/Normalization/normalizers.js +2 -0
- package/lib/Select/BooleanSelectGroup.d.ts +2 -1
- package/lib/Select/BooleanSelectGroup.js +1 -0
- package/lib/Select/NumberSelectGroup.d.ts +4 -2
- package/lib/Select/NumberSelectGroup.js +2 -0
- package/lib/Select/SelectGroup.d.ts +8 -2
- package/lib/Select/SelectGroup.js +5 -4
- package/lib/Select/StringSelectGroup.d.ts +2 -0
- package/lib/Select/StringSelectGroup.js +2 -0
- package/lib/StandardFormActions.d.ts +5 -0
- package/lib/StandardFormActions.js +1 -0
- package/lib/SubmitFormButton.d.ts +4 -1
- package/lib/SubmitFormButton.js +1 -0
- package/lib/TextArea/TextAreaGroup.d.ts +2 -1
- package/lib/TextArea/TextAreaGroup.js +5 -4
- package/lib/Validation/validators.d.ts +11 -8
- package/lib/Validation/validators.js +6 -2
- package/lib/hooks/index.d.ts +2 -0
- package/lib/{__Tests__ → hooks}/index.js +3 -3
- package/lib/hooks/useFormValue.d.ts +2 -0
- package/lib/hooks/useFormValue.js +10 -0
- package/lib/index.d.ts +10 -4
- package/lib/index.js +8 -1
- package/lib/setupTests.d.ts +1 -0
- package/lib/setupTests.js +3 -0
- package/package.json +12 -8
- package/src/AddressInput/AddressInput.tsx +15 -5
- package/src/AddressInput/__snapshots__/AddressInput.test.tsx.snap +8 -4
- package/src/ConfirmBaseForm/ConfirmBaseForm.tsx +14 -0
- package/src/ConfirmDeleteForm/ConfirmDeleteForm.tsx +13 -0
- package/src/DatePicker/DatePicker.test.tsx +1 -1
- package/src/DatePicker/DatePickerGroup.tsx +23 -7
- package/src/DatePicker/StringDateOnlyPickerGroup.tsx +7 -2
- package/src/DatePicker/StringDatePickerGroup.tsx +7 -1
- package/src/DateTimePicker/DateTimePicker.test.tsx +243 -0
- package/src/DateTimePicker/DateTimePickerGroup.tsx +116 -0
- package/src/DateTimePicker/DateTimePickerHelper.ts +4 -0
- package/src/DateTimePicker/StringDateTimePickerGroup.tsx +61 -0
- package/src/DateTimePicker/__snapshots__/DateTimePicker.test.tsx.snap +216 -0
- package/src/Field/Field.tsx +20 -7
- package/src/Field/FieldErrorScrollTarget.tsx +1 -0
- package/src/Field/StandAloneInput.tsx +4 -0
- package/src/Field/useStandardField.ts +13 -9
- package/src/FieldArray/FieldArray.tsx +14 -5
- package/src/File/FileGroup.tsx +9 -3
- package/src/File/FileList.tsx +2 -2
- package/src/Form/FocusError.tsx +3 -0
- package/src/Form/Form.tsx +6 -0
- package/src/Form/FormBasedPreventNavigation.tsx +28 -46
- package/src/Form/LegacyFormBasedPreventNavigation.tsx +77 -0
- package/src/Form/NewFormBasedPreventNavigation.tsx +59 -0
- package/src/Form/ServerErrorContext.ts +1 -0
- package/src/FormActions.tsx +7 -0
- package/src/FormDefaults.ts +1 -0
- package/src/Group.tsx +12 -4
- package/src/Input/IconInputGroup.tsx +5 -2
- package/src/Input/InputGroup.tsx +13 -5
- package/src/Input/MoneyInputGroup.tsx +3 -1
- package/src/Input/NumberInputGroup.tsx +3 -1
- package/src/Input/PhoneNumberInputGroup.tsx +49 -0
- package/src/Input/StringInputGroup.tsx +3 -2
- package/src/Input/__Tests__/PhoneNumberInputGroup.test.tsx +37 -0
- package/src/Input/__Tests__/__snapshots__/IconInputGroup.test.tsx.snap +1 -0
- package/src/Input/__Tests__/__snapshots__/MoneyInputGroup.test.tsx.snap +1 -0
- package/src/Input/__Tests__/__snapshots__/NumberInputGroup.test.tsx.snap +1 -0
- package/src/Input/__Tests__/__snapshots__/PhoneNumberInputGroup.test.tsx.snap +33 -0
- package/src/Input/__Tests__/__snapshots__/StringInputGroup.test.tsx.snap +1 -0
- package/src/Normalization/normalizers.ts +4 -2
- package/src/Select/BooleanSelectGroup.tsx +2 -1
- package/src/Select/NumberSelectGroup.tsx +4 -2
- package/src/Select/SelectGroup.tsx +13 -2
- package/src/Select/StringSelectGroup.tsx +2 -0
- package/src/StandardFormActions.tsx +5 -0
- package/src/SubmitFormButton.tsx +5 -1
- package/src/TextArea/TextAreaGroup.tsx +6 -4
- package/src/Validation/validators.ts +19 -14
- package/src/__Tests__/FormTestBase.tsx +10 -8
- package/src/__Tests__/RealisticForm.test.tsx +82 -0
- package/src/hooks/index.ts +3 -0
- package/src/hooks/useFormValue.ts +16 -0
- package/src/index.ts +14 -4
- package/src/setupTests.ts +1 -0
- package/es/__Tests__/FormTestBase.d.ts +0 -27
- package/es/__Tests__/FormTestBase.js +0 -83
- package/es/__Tests__/index.d.ts +0 -2
- package/es/__Tests__/index.js +0 -2
- package/lib/__Tests__/FormTestBase.d.ts +0 -27
- package/lib/__Tests__/FormTestBase.js +0 -86
- package/lib/__Tests__/index.d.ts +0 -2
@@ -0,0 +1,216 @@
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
2
|
+
|
3
|
+
exports[`StringDateTimePickerGroup has matching snapshot 1`] = `
|
4
|
+
<DocumentFragment>
|
5
|
+
<form
|
6
|
+
action="#"
|
7
|
+
class="envoc-form-form"
|
8
|
+
>
|
9
|
+
<div
|
10
|
+
class="envoc-form-date-time-picker envoc-form-group"
|
11
|
+
>
|
12
|
+
<div
|
13
|
+
id="createddatetime-error-scroll-target"
|
14
|
+
style="display: none;"
|
15
|
+
/>
|
16
|
+
<label
|
17
|
+
for="createdDateTime"
|
18
|
+
>
|
19
|
+
Created Date Time
|
20
|
+
</label>
|
21
|
+
<div
|
22
|
+
class="react-datetime-picker react-datetime-picker--closed react-datetime-picker--enabled envoc-form-date-time-picker"
|
23
|
+
id="createdDateTime"
|
24
|
+
>
|
25
|
+
<div
|
26
|
+
class="react-datetime-picker__wrapper"
|
27
|
+
>
|
28
|
+
<div
|
29
|
+
class="react-datetime-picker__inputGroup"
|
30
|
+
>
|
31
|
+
<input
|
32
|
+
hidden=""
|
33
|
+
max="2023-09-23T00:00"
|
34
|
+
min="2022-06-22T00:00"
|
35
|
+
name="datetime"
|
36
|
+
step="60"
|
37
|
+
style="visibility: hidden; position: absolute; z-index: -999;"
|
38
|
+
type="datetime-local"
|
39
|
+
value=""
|
40
|
+
/>
|
41
|
+
<input
|
42
|
+
autocomplete="off"
|
43
|
+
class="react-datetime-picker__inputGroup__input react-datetime-picker__inputGroup__month"
|
44
|
+
data-input="true"
|
45
|
+
inputmode="numeric"
|
46
|
+
max="12"
|
47
|
+
min="1"
|
48
|
+
name="month"
|
49
|
+
placeholder="mm"
|
50
|
+
type="number"
|
51
|
+
value=""
|
52
|
+
/>
|
53
|
+
<span
|
54
|
+
class="react-datetime-picker__inputGroup__divider"
|
55
|
+
>
|
56
|
+
/
|
57
|
+
</span>
|
58
|
+
<input
|
59
|
+
autocomplete="off"
|
60
|
+
class="react-datetime-picker__inputGroup__input react-datetime-picker__inputGroup__day"
|
61
|
+
data-input="true"
|
62
|
+
inputmode="numeric"
|
63
|
+
max="31"
|
64
|
+
min="1"
|
65
|
+
name="day"
|
66
|
+
placeholder="dd"
|
67
|
+
type="number"
|
68
|
+
value=""
|
69
|
+
/>
|
70
|
+
<span
|
71
|
+
class="react-datetime-picker__inputGroup__divider"
|
72
|
+
>
|
73
|
+
/
|
74
|
+
</span>
|
75
|
+
<input
|
76
|
+
autocomplete="off"
|
77
|
+
class="react-datetime-picker__inputGroup__input react-datetime-picker__inputGroup__year"
|
78
|
+
data-input="true"
|
79
|
+
inputmode="numeric"
|
80
|
+
max="2023"
|
81
|
+
min="2022"
|
82
|
+
name="year"
|
83
|
+
placeholder="yyyy"
|
84
|
+
step="1"
|
85
|
+
type="number"
|
86
|
+
value=""
|
87
|
+
/>
|
88
|
+
<span
|
89
|
+
class="react-datetime-picker__inputGroup__divider"
|
90
|
+
>
|
91
|
+
|
92
|
+
</span>
|
93
|
+
<input
|
94
|
+
autocomplete="off"
|
95
|
+
class="react-datetime-picker__inputGroup__input react-datetime-picker__inputGroup__hour"
|
96
|
+
data-input="true"
|
97
|
+
inputmode="numeric"
|
98
|
+
max="12"
|
99
|
+
min="1"
|
100
|
+
name="hour12"
|
101
|
+
placeholder="--"
|
102
|
+
type="number"
|
103
|
+
value=""
|
104
|
+
/>
|
105
|
+
<span
|
106
|
+
class="react-datetime-picker__inputGroup__divider"
|
107
|
+
>
|
108
|
+
:
|
109
|
+
</span>
|
110
|
+
<input
|
111
|
+
autocomplete="off"
|
112
|
+
class="react-datetime-picker__inputGroup__input react-datetime-picker__inputGroup__minute"
|
113
|
+
data-input="true"
|
114
|
+
inputmode="numeric"
|
115
|
+
max="59"
|
116
|
+
min="0"
|
117
|
+
name="minute"
|
118
|
+
placeholder="--"
|
119
|
+
type="number"
|
120
|
+
value=""
|
121
|
+
/>
|
122
|
+
<span
|
123
|
+
class="react-datetime-picker__inputGroup__divider"
|
124
|
+
>
|
125
|
+
|
126
|
+
</span>
|
127
|
+
<select
|
128
|
+
class="react-datetime-picker__inputGroup__input react-datetime-picker__inputGroup__amPm"
|
129
|
+
data-input="true"
|
130
|
+
data-select="true"
|
131
|
+
name="amPm"
|
132
|
+
>
|
133
|
+
<option
|
134
|
+
value=""
|
135
|
+
>
|
136
|
+
--
|
137
|
+
</option>
|
138
|
+
<option
|
139
|
+
value="am"
|
140
|
+
>
|
141
|
+
AM
|
142
|
+
</option>
|
143
|
+
<option
|
144
|
+
value="pm"
|
145
|
+
>
|
146
|
+
PM
|
147
|
+
</option>
|
148
|
+
</select>
|
149
|
+
</div>
|
150
|
+
<button
|
151
|
+
class="react-datetime-picker__clear-button react-datetime-picker__button"
|
152
|
+
type="button"
|
153
|
+
>
|
154
|
+
<svg
|
155
|
+
class="react-datetime-picker__clear-button__icon react-datetime-picker__button__icon"
|
156
|
+
height="19"
|
157
|
+
stroke="black"
|
158
|
+
stroke-width="2"
|
159
|
+
viewBox="0 0 19 19"
|
160
|
+
width="19"
|
161
|
+
xmlns="http://www.w3.org/2000/svg"
|
162
|
+
>
|
163
|
+
<line
|
164
|
+
x1="4"
|
165
|
+
x2="15"
|
166
|
+
y1="4"
|
167
|
+
y2="15"
|
168
|
+
/>
|
169
|
+
<line
|
170
|
+
x1="15"
|
171
|
+
x2="4"
|
172
|
+
y1="4"
|
173
|
+
y2="15"
|
174
|
+
/>
|
175
|
+
</svg>
|
176
|
+
</button>
|
177
|
+
<button
|
178
|
+
class="react-datetime-picker__calendar-button react-datetime-picker__button"
|
179
|
+
type="button"
|
180
|
+
>
|
181
|
+
<svg
|
182
|
+
class="react-datetime-picker__calendar-button__icon react-datetime-picker__button__icon"
|
183
|
+
height="19"
|
184
|
+
stroke="black"
|
185
|
+
stroke-width="2"
|
186
|
+
viewBox="0 0 19 19"
|
187
|
+
width="19"
|
188
|
+
xmlns="http://www.w3.org/2000/svg"
|
189
|
+
>
|
190
|
+
<rect
|
191
|
+
fill="none"
|
192
|
+
height="15"
|
193
|
+
width="15"
|
194
|
+
x="2"
|
195
|
+
y="2"
|
196
|
+
/>
|
197
|
+
<line
|
198
|
+
x1="6"
|
199
|
+
x2="6"
|
200
|
+
y1="0"
|
201
|
+
y2="4"
|
202
|
+
/>
|
203
|
+
<line
|
204
|
+
x1="13"
|
205
|
+
x2="13"
|
206
|
+
y1="0"
|
207
|
+
y2="4"
|
208
|
+
/>
|
209
|
+
</svg>
|
210
|
+
</button>
|
211
|
+
</div>
|
212
|
+
</div>
|
213
|
+
</div>
|
214
|
+
</form>
|
215
|
+
</DocumentFragment>
|
216
|
+
`;
|
package/src/Field/Field.tsx
CHANGED
@@ -4,6 +4,7 @@ import { InjectedFieldProps } from './InjectedFieldProps';
|
|
4
4
|
import useStandardFormInput from './useStandardField';
|
5
5
|
import { NormalizationFunction } from '../Normalization/NormalizationFunction';
|
6
6
|
import { ValidationFunction } from '../Validation/ValidationFunction';
|
7
|
+
import { required as requiredValidator } from '../Validation/validators';
|
7
8
|
|
8
9
|
// we attempted to support generic components but failed
|
9
10
|
// so, we assume the actual TRenderComponent has no generic arguments
|
@@ -13,7 +14,7 @@ export type RenderComponent<
|
|
13
14
|
TValue,
|
14
15
|
TRenderComponent extends ElementType
|
15
16
|
> = Partial<ComponentProps<TRenderComponent>> extends Partial<
|
16
|
-
InjectedFieldProps<TValue | undefined>
|
17
|
+
InjectedFieldProps<TValue | undefined | null>
|
17
18
|
>
|
18
19
|
? TRenderComponent
|
19
20
|
: never;
|
@@ -22,7 +23,7 @@ export type RenderComponentProps<
|
|
22
23
|
TValue,
|
23
24
|
TRenderComponent extends ElementType
|
24
25
|
> = Partial<ComponentProps<TRenderComponent>> extends Partial<
|
25
|
-
InjectedFieldProps<TValue | undefined>
|
26
|
+
InjectedFieldProps<TValue | undefined | null>
|
26
27
|
>
|
27
28
|
? ComponentProps<TRenderComponent>
|
28
29
|
: never;
|
@@ -33,14 +34,19 @@ export type FieldProps<
|
|
33
34
|
TProp extends keyof TForm,
|
34
35
|
TRenderComponent extends ElementType
|
35
36
|
> = {
|
37
|
+
/** Name of the field. Used on submission. */
|
36
38
|
name: TProp; // somewhat duplicated from useStandardFormInputProps but better for autocomplete
|
39
|
+
/** Component to be rendered. Usually this is a type of input group e.g. `<StringInputGroup/>` */
|
37
40
|
Component: RenderComponent<TForm[TProp], TRenderComponent>;
|
38
|
-
|
41
|
+
/** Id of the field. */
|
39
42
|
id?: string;
|
43
|
+
/** Whether the field should be disabled. */
|
40
44
|
disabled?: boolean;
|
45
|
+
/** Client side validation functions */
|
41
46
|
validate?:
|
42
47
|
| ValidationFunction<TForm[TProp]>
|
43
48
|
| ValidationFunction<TForm[TProp]>[];
|
49
|
+
/** Function to modify the field value without making the form dirty. (e.g. phone number) */
|
44
50
|
normalize?: NormalizationFunction<TForm[TProp]>;
|
45
51
|
} & Omit<
|
46
52
|
RenderComponentProps<TForm[TProp], TRenderComponent>,
|
@@ -60,9 +66,9 @@ function Field<
|
|
60
66
|
name,
|
61
67
|
Component,
|
62
68
|
id,
|
63
|
-
normalize,
|
64
|
-
validate,
|
65
69
|
disabled,
|
70
|
+
validate,
|
71
|
+
normalize,
|
66
72
|
...rest
|
67
73
|
}: FieldProps<TForm, TProp, TRenderComponent>,
|
68
74
|
ref: LegacyRef<any>
|
@@ -70,11 +76,17 @@ function Field<
|
|
70
76
|
const [input, meta] = useStandardFormInput<TForm[TProp]>({
|
71
77
|
name: String(name),
|
72
78
|
id: id,
|
73
|
-
normalize: normalize,
|
74
|
-
validate: validate,
|
75
79
|
disabled: disabled,
|
80
|
+
validate: validate,
|
81
|
+
normalize: normalize,
|
76
82
|
});
|
77
83
|
|
84
|
+
const isRequired =
|
85
|
+
rest?.required !== undefined
|
86
|
+
? rest.required
|
87
|
+
: validate === requiredValidator ||
|
88
|
+
(Array.isArray(validate) && validate.includes(requiredValidator));
|
89
|
+
|
78
90
|
// a bit of a hack so JSX is happy with us
|
79
91
|
const Wrapped = Component as React.ComponentType<
|
80
92
|
InjectedFieldProps<TForm[TProp]>
|
@@ -88,6 +100,7 @@ function Field<
|
|
88
100
|
id={input.id}
|
89
101
|
input={input}
|
90
102
|
meta={meta}
|
103
|
+
required={isRequired}
|
91
104
|
disabled={disabled}
|
92
105
|
/>
|
93
106
|
</FieldNameContext.Provider>
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { useContext } from 'react';
|
2
2
|
import { FieldNameContext } from './FieldNameContext';
|
3
3
|
|
4
|
+
/** Hidden `<div/>` that acts as an anchor to scroll to when a form error occurs. */
|
4
5
|
export default function FieldErrorScrollTarget() {
|
5
6
|
const name = useContext(FieldNameContext);
|
6
7
|
if (!name) {
|
@@ -9,8 +9,11 @@ export type StandAloneInputProps<
|
|
9
9
|
TValue,
|
10
10
|
TRenderComponent extends ElementType
|
11
11
|
> = {
|
12
|
+
/** Component to render inside of the field. */
|
12
13
|
Component: RenderComponent<TValue, TRenderComponent>;
|
14
|
+
/** Value of the field. */
|
13
15
|
value: TValue;
|
16
|
+
/** Function to change the value of the field. */
|
14
17
|
onChange: (arg: TValue) => void;
|
15
18
|
} & Omit<
|
16
19
|
RenderComponentProps<TValue, TRenderComponent>,
|
@@ -21,6 +24,7 @@ export type StandAloneInputProps<
|
|
21
24
|
| 'validate'
|
22
25
|
>;
|
23
26
|
|
27
|
+
/** The stand alone version of `<Field/>`. Can use a type of input component outside of a `<Form/>`. */
|
24
28
|
export default function StandAloneInput<TValue, TComponent extends ElementType>(
|
25
29
|
props: StandAloneInputProps<TValue, TComponent>
|
26
30
|
) {
|
@@ -8,14 +8,19 @@ import { NormalizationFunction } from '../Normalization/NormalizationFunction';
|
|
8
8
|
import { ValidationFunction } from '../Validation/ValidationFunction';
|
9
9
|
|
10
10
|
export interface useStandardFieldProps<TValue> {
|
11
|
+
/** Id of the field. */
|
11
12
|
id?: string;
|
13
|
+
/** Name of the field. */
|
12
14
|
name: string;
|
15
|
+
/** Whether the field should be disabled. */
|
13
16
|
disabled?: boolean;
|
17
|
+
/** Function to validate the field. */
|
14
18
|
validate?: ValidationFunction<TValue> | ValidationFunction<TValue>[];
|
19
|
+
/** Function to modify the field value without making the form dirty. (e.g. phone number) */
|
15
20
|
normalize?: NormalizationFunction<TValue>;
|
16
21
|
}
|
17
22
|
|
18
|
-
|
23
|
+
/** Provides a consistent way to deal with all form fields (non array). */
|
19
24
|
export default function useStandardField<TValue>({
|
20
25
|
id: providedId,
|
21
26
|
name: providedName,
|
@@ -51,7 +56,7 @@ export default function useStandardField<TValue>({
|
|
51
56
|
disabled: disabled,
|
52
57
|
validate: callAllValidators,
|
53
58
|
});
|
54
|
-
const { setFieldValue, isSubmitting } = useFormikContext();
|
59
|
+
const { setFieldTouched, setFieldValue, isSubmitting } = useFormikContext();
|
55
60
|
|
56
61
|
const touched =
|
57
62
|
formikMeta.touched !== false && formikMeta.touched !== undefined;
|
@@ -59,14 +64,13 @@ export default function useStandardField<TValue>({
|
|
59
64
|
if (!touched && isSubmitting) {
|
60
65
|
// because we do not always register all fields up front.
|
61
66
|
// e.g. formik expects even a 'create' form to have all fields given, at least, blank values
|
62
|
-
//
|
63
|
-
//
|
64
|
-
//
|
65
|
-
//
|
66
|
-
|
67
|
-
handleBlur();
|
67
|
+
// It looks like this was going to be a thing: https://github.com/jaredpalmer/formik/issues/691
|
68
|
+
// Formik appears to not have an active maintainer: https://github.com/jaredpalmer/formik/discussions/3526
|
69
|
+
// We previously had a different fix in place using handleBlur, but it was causing an infinite update cycle.
|
70
|
+
// This was noted as existing, but there was a note about it not working for FieldArray (this does appear to work in my testing with FieldArray)
|
71
|
+
setFieldTouched(name);
|
68
72
|
}
|
69
|
-
});
|
73
|
+
}, [isSubmitting, name, setFieldTouched, touched]);
|
70
74
|
|
71
75
|
// these are the props we expect consumers of this hook to pass directly to the input (or other control)
|
72
76
|
const resultInput: CustomFieldInputProps<TValue> = {
|
@@ -3,17 +3,21 @@ import classNames from 'classnames';
|
|
3
3
|
import Field, { FieldProps } from '../Field/Field';
|
4
4
|
import { FieldNameContext } from '../Field/FieldNameContext';
|
5
5
|
import useStandardFormInput from '../Field/useStandardField';
|
6
|
-
import { ValidationFunction } from '../Validation/ValidationFunction';
|
7
6
|
import { FormDefaults } from '../FormDefaults';
|
7
|
+
import { ValidationFunction } from '../Validation/ValidationFunction';
|
8
8
|
|
9
9
|
export type FieldArrayProps<
|
10
10
|
TForm extends object,
|
11
11
|
TProp extends keyof TForm
|
12
|
-
> = TForm[TProp] extends Array<any> | undefined
|
12
|
+
> = TForm[TProp] extends Array<any> | undefined | null
|
13
13
|
? {
|
14
|
+
/** Name of the field, used on submission. If using codegen this must be the provided dto. */
|
14
15
|
name: TProp;
|
16
|
+
/** Label of the field. */
|
15
17
|
label?: string;
|
18
|
+
/** Whether the field should be disabled. */
|
16
19
|
disabled?: boolean;
|
20
|
+
/** Function to validate the value. */
|
17
21
|
validate?:
|
18
22
|
| ValidationFunction<TForm[TProp]>
|
19
23
|
| ValidationFunction<TForm[TProp]>[];
|
@@ -23,8 +27,8 @@ export type FieldArrayProps<
|
|
23
27
|
}
|
24
28
|
: never;
|
25
29
|
|
26
|
-
export type ArrayFormBuilderProp<TValue extends Array<any> | undefined> =
|
27
|
-
TValue extends Array<infer TForm> | undefined
|
30
|
+
export type ArrayFormBuilderProp<TValue extends Array<any> | undefined | null> =
|
31
|
+
TValue extends Array<infer TForm> | undefined | null
|
28
32
|
? TForm extends object
|
29
33
|
? {
|
30
34
|
Field: <
|
@@ -41,6 +45,11 @@ export type ArrayFormBuilderProp<TValue extends Array<any> | undefined> =
|
|
41
45
|
: never
|
42
46
|
: never;
|
43
47
|
|
48
|
+
/**
|
49
|
+
* An array of fields that allows the user to add multiple instances of the same field.
|
50
|
+
*
|
51
|
+
* Includes "Add Item" and "Remove Item" buttons to allow the user to speicify the number of fields.
|
52
|
+
*/
|
44
53
|
export default function FieldArray<
|
45
54
|
TForm extends object,
|
46
55
|
TProp extends keyof TForm
|
@@ -52,7 +61,7 @@ export default function FieldArray<
|
|
52
61
|
children,
|
53
62
|
...rest
|
54
63
|
}: FieldArrayProps<TForm, TProp>) {
|
55
|
-
const [input
|
64
|
+
const [input] = useStandardFormInput<TForm[TProp]>({
|
56
65
|
name: String(name),
|
57
66
|
validate: validate,
|
58
67
|
disabled: disabled,
|
package/src/File/FileGroup.tsx
CHANGED
@@ -2,17 +2,18 @@ import React, { ComponentType, LegacyRef } from 'react';
|
|
2
2
|
import classNames from 'classnames';
|
3
3
|
import FileList from './FileList';
|
4
4
|
import { InjectedFieldProps } from '../Field/InjectedFieldProps';
|
5
|
-
import Group, { GroupProps } from '../Group';
|
6
5
|
import { FormDefaults } from '../FormDefaults';
|
6
|
+
import Group, { GroupProps } from '../Group';
|
7
7
|
|
8
8
|
export interface FileGroupProps
|
9
9
|
// note: file props are of type "any" with the current type generation
|
10
|
-
extends InjectedFieldProps<any | undefined>,
|
10
|
+
extends InjectedFieldProps<any | undefined | null>,
|
11
11
|
Omit<GroupProps, keyof InjectedFieldProps<any> | 'children'>,
|
12
12
|
Omit<
|
13
13
|
React.HTMLProps<HTMLInputElement>,
|
14
14
|
keyof InjectedFieldProps<any> | 'children' | 'className' | 'label'
|
15
15
|
> {
|
16
|
+
/** Allow multiple files to be uploaded. */
|
16
17
|
multiple?: boolean | undefined;
|
17
18
|
}
|
18
19
|
|
@@ -23,6 +24,8 @@ function FileGroup(
|
|
23
24
|
label,
|
24
25
|
helpText,
|
25
26
|
className,
|
27
|
+
required,
|
28
|
+
disabled,
|
26
29
|
multiple,
|
27
30
|
...rest
|
28
31
|
}: FileGroupProps,
|
@@ -38,7 +41,9 @@ function FileGroup(
|
|
38
41
|
className,
|
39
42
|
{ [FormDefaults.cssClassPrefix + 'multiple']: multiple },
|
40
43
|
FormDefaults.cssClassPrefix + 'file-group'
|
41
|
-
)}
|
44
|
+
)}
|
45
|
+
required={required}
|
46
|
+
disabled={disabled}>
|
42
47
|
<input
|
43
48
|
{...input}
|
44
49
|
{...rest}
|
@@ -72,6 +77,7 @@ function FileGroup(
|
|
72
77
|
);
|
73
78
|
}
|
74
79
|
|
80
|
+
/** File upload input group. */
|
75
81
|
const FileGroupWithRef = React.forwardRef(
|
76
82
|
FileGroup
|
77
83
|
) as ComponentType<FileGroupProps>;
|
package/src/File/FileList.tsx
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import { FormDefaults } from '../FormDefaults';
|
2
2
|
|
3
3
|
export interface FileListProps {
|
4
|
-
files?: File | File[] | undefined;
|
5
|
-
rejectedFiles?: File | File[] | undefined;
|
4
|
+
files?: File | File[] | undefined | null;
|
5
|
+
rejectedFiles?: File | File[] | undefined | null;
|
6
6
|
}
|
7
7
|
export default function FileList({ files, rejectedFiles }: FileListProps) {
|
8
8
|
return (
|
package/src/Form/FocusError.tsx
CHANGED
@@ -4,8 +4,11 @@ import smoothscroll from 'smoothscroll-polyfill';
|
|
4
4
|
import { ServerErrorContextProps } from './ServerErrorContext';
|
5
5
|
|
6
6
|
export interface FocusErrorProps {
|
7
|
+
/** Validation errors that have been received from the server. */
|
7
8
|
serverErrors: ServerErrorContextProps;
|
8
9
|
}
|
10
|
+
|
11
|
+
/** Function to scroll to the field that has an error. */
|
9
12
|
export default function FocusError(props: FocusErrorProps) {
|
10
13
|
const { errors, isSubmitting, isValidating } = useFormikContext();
|
11
14
|
smoothscroll.polyfill();
|
package/src/Form/Form.tsx
CHANGED
@@ -41,18 +41,23 @@ export type FormBuilderProp<TForm extends object> = {
|
|
41
41
|
};
|
42
42
|
|
43
43
|
export interface FullFormProps<TForm extends object> {
|
44
|
+
/** The `<Field/>` and `<FieldArray/>` components. */
|
44
45
|
children: (formBuilder: FormBuilderProp<TForm>) => JSX.Element;
|
46
|
+
/** Submission handler */
|
45
47
|
onSubmit: (
|
46
48
|
formValues: TForm,
|
47
49
|
formikBag: FormikHelpers<TForm>
|
48
50
|
) => Promise<ValidatedApiResult>;
|
51
|
+
/** Submission handler for forms that use [FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData).*/
|
49
52
|
onFormDataSubmit: (
|
50
53
|
formValues: FormData,
|
51
54
|
formikBag: FormikHelpers<TForm>
|
52
55
|
) => Promise<ValidatedApiResult>;
|
53
56
|
className?: string;
|
54
57
|
style?: CSSProperties;
|
58
|
+
/** Prevent the user from leaving the form if they have edited any field. This is presented as a JS `alert()`. */
|
55
59
|
ignoreLostChanges?: boolean;
|
60
|
+
/** The intitial values of the form. */
|
56
61
|
initialValues?: TForm;
|
57
62
|
}
|
58
63
|
|
@@ -69,6 +74,7 @@ export type FormProps<TForm extends object> = RequireAtLeastOne<
|
|
69
74
|
'onSubmit' | 'onFormDataSubmit'
|
70
75
|
>;
|
71
76
|
|
77
|
+
/** Define a form. Uses [formik](https://formik.org/docs/overview). Usually contains many `<Field/>` components. */
|
72
78
|
export default function Form<TForm extends object>({
|
73
79
|
children,
|
74
80
|
className,
|
@@ -1,16 +1,18 @@
|
|
1
|
-
import type { History
|
2
|
-
import { ContextType, useContext
|
3
|
-
// see: https://gist.github.com/rmorse/426ffcc579922a82749934826fa9f743
|
1
|
+
import type { History } from 'history';
|
2
|
+
import { ContextType, useContext } from 'react';
|
4
3
|
import {
|
5
4
|
Navigator as BaseNavigator,
|
6
5
|
UNSAFE_NavigationContext as NavigationContext,
|
7
6
|
} from 'react-router-dom';
|
8
7
|
import { useFormikContext } from 'formik';
|
8
|
+
import LegacyFormBasedPreventNavigation from './LegacyFormBasedPreventNavigation';
|
9
|
+
import NewFormBasedPreventNavigation from './NewFormBasedPreventNavigation';
|
9
10
|
|
10
11
|
interface Navigator extends BaseNavigator {
|
11
|
-
block
|
12
|
+
block?: History['block'];
|
13
|
+
location: Location;
|
12
14
|
}
|
13
|
-
|
15
|
+
|
14
16
|
type NavigationContextWithBlock = ContextType<typeof NavigationContext> & {
|
15
17
|
navigator: Navigator;
|
16
18
|
};
|
@@ -19,6 +21,8 @@ export interface FormBasedPreventNavigationProps {
|
|
19
21
|
ignoreLostChanges?: boolean;
|
20
22
|
promptMessage?: string;
|
21
23
|
}
|
24
|
+
|
25
|
+
/** Prevent the user from navigating away from a form if there are any changes. */
|
22
26
|
export default function FormBasedPreventNavigation({
|
23
27
|
ignoreLostChanges,
|
24
28
|
promptMessage = 'Changes you made may not be saved.',
|
@@ -30,45 +34,23 @@ export default function FormBasedPreventNavigation({
|
|
30
34
|
NavigationContext
|
31
35
|
) as NavigationContextWithBlock;
|
32
36
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
// this block if the transition is cancelled for some reason.
|
53
|
-
unblock();
|
54
|
-
tx.retry();
|
55
|
-
},
|
56
|
-
};
|
57
|
-
|
58
|
-
blocker(autoUnblockingTx);
|
59
|
-
});
|
60
|
-
|
61
|
-
window.addEventListener('beforeunload', beforeUnload);
|
62
|
-
return () => {
|
63
|
-
unblock();
|
64
|
-
window.removeEventListener('beforeunload', beforeUnload);
|
65
|
-
};
|
66
|
-
|
67
|
-
function beforeUnload(e: BeforeUnloadEvent) {
|
68
|
-
e.preventDefault();
|
69
|
-
e.returnValue = promptMessage;
|
70
|
-
}
|
71
|
-
}, [preventNavigate, promptMessage, navigator]);
|
72
|
-
|
73
|
-
return null;
|
37
|
+
const isUsingDataRouter = navigator.location === undefined;
|
38
|
+
|
39
|
+
if (isUsingDataRouter) {
|
40
|
+
return (
|
41
|
+
<NewFormBasedPreventNavigation
|
42
|
+
promptMessage={promptMessage}
|
43
|
+
preventNavigate={preventNavigate}
|
44
|
+
navigator={navigator}
|
45
|
+
/>
|
46
|
+
);
|
47
|
+
} else {
|
48
|
+
return (
|
49
|
+
<LegacyFormBasedPreventNavigation
|
50
|
+
promptMessage={promptMessage}
|
51
|
+
preventNavigate={preventNavigate}
|
52
|
+
navigator={navigator}
|
53
|
+
/>
|
54
|
+
);
|
55
|
+
}
|
74
56
|
}
|