@digigov/form 2.0.0-e7d30530 → 2.0.0-eaf330f5

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.
Files changed (268) hide show
  1. package/Field/FieldBase/index.js +4 -3
  2. package/Field/FieldBase.js.map +2 -2
  3. package/Field/FieldBaseContainer/index.js +19 -37
  4. package/Field/FieldBaseContainer.d.ts +1 -1
  5. package/Field/FieldBaseContainer.js.map +2 -2
  6. package/Field/FieldConditional/index.js +1 -1
  7. package/Field/FieldConditional.js.map +1 -1
  8. package/Field/index.js +1 -2
  9. package/Field/index.js.map +2 -2
  10. package/Field/types.d.ts +2 -2
  11. package/Field/utils/index.js +3 -4
  12. package/Field/utils/index.js.map +2 -2
  13. package/FieldArray/FormDialog/index.js +7 -2
  14. package/FieldArray/FormDialog.d.ts +3 -2
  15. package/FieldArray/FormDialog.js.map +2 -2
  16. package/FieldArray/__stories__/Default.d.ts +1 -1
  17. package/FieldArray/__stories__/WithExactLength.d.ts +1 -1
  18. package/FieldArray/__stories__/WithModal.d.ts +1 -1
  19. package/FieldArray/index.d.ts +1 -1
  20. package/FieldArray/index.js +88 -95
  21. package/FieldArray/index.js.map +3 -3
  22. package/FormBuilder/FormBuilder.stories.d.ts +0 -2
  23. package/FormBuilder/__stories__/AutoErrorGrouping.d.ts +1 -1
  24. package/FormBuilder/__stories__/Default.d.ts +1 -1
  25. package/FormBuilder/__stories__/ErrorGrouping.d.ts +1 -1
  26. package/FormBuilder/index.d.ts +1 -1
  27. package/FormBuilder/index.js +7 -3
  28. package/FormBuilder/index.js.map +2 -2
  29. package/FormContext/index.js +2 -6
  30. package/FormContext.d.ts +0 -1
  31. package/FormContext.js.map +2 -2
  32. package/MultiplicityField/MultiplicityField.stories.d.ts +0 -2
  33. package/MultiplicityField/__stories__/Default.d.ts +1 -1
  34. package/MultiplicityField/__stories__/PreviewDisplay.d.ts +1 -1
  35. package/MultiplicityField/__stories__/WithExactLength.d.ts +1 -1
  36. package/MultiplicityField/__stories__/WithMaxLength.d.ts +1 -1
  37. package/MultiplicityField/__stories__/WithMinAndMaxLength.d.ts +1 -1
  38. package/MultiplicityField/__stories__/WithMinLength.d.ts +1 -1
  39. package/MultiplicityField/add-objects/index.js +1 -1
  40. package/MultiplicityField/add-objects.js.map +2 -2
  41. package/MultiplicityField/index.js +2 -4
  42. package/MultiplicityField/index.js.map +2 -2
  43. package/MultiplicityField/types.d.ts +0 -1
  44. package/Questions/Questions.stories.d.ts +0 -2
  45. package/Questions/__stories__/Default.d.ts +1 -1
  46. package/cjs/Field/FieldBase/index.js +4 -3
  47. package/cjs/Field/FieldBase.js.map +2 -2
  48. package/cjs/Field/FieldBaseContainer/index.js +18 -36
  49. package/cjs/Field/FieldBaseContainer.js.map +3 -3
  50. package/cjs/Field/FieldConditional/index.js +1 -1
  51. package/cjs/Field/FieldConditional.js.map +1 -1
  52. package/cjs/Field/index.js +1 -2
  53. package/cjs/Field/index.js.map +2 -2
  54. package/cjs/Field/types.js.map +1 -1
  55. package/cjs/Field/utils/index.js +3 -4
  56. package/cjs/Field/utils/index.js.map +2 -2
  57. package/cjs/FieldArray/FormDialog/index.js +7 -2
  58. package/cjs/FieldArray/FormDialog.js.map +2 -2
  59. package/cjs/FieldArray/index.js +83 -93
  60. package/cjs/FieldArray/index.js.map +3 -3
  61. package/cjs/FormBuilder/index.js +7 -3
  62. package/cjs/FormBuilder/index.js.map +2 -2
  63. package/cjs/FormContext/index.js +2 -7
  64. package/cjs/FormContext.js.map +2 -2
  65. package/cjs/MultiplicityField/add-objects/index.js +1 -1
  66. package/cjs/MultiplicityField/add-objects.js.map +2 -2
  67. package/cjs/MultiplicityField/index.js +2 -4
  68. package/cjs/MultiplicityField/index.js.map +2 -2
  69. package/cjs/MultiplicityField/types.js.map +1 -1
  70. package/cjs/inputs/Checkboxes/index.js +1 -2
  71. package/cjs/inputs/Checkboxes/index.js.map +2 -2
  72. package/cjs/inputs/DateInput/index.js +12 -27
  73. package/cjs/inputs/DateInput/index.js.map +2 -2
  74. package/cjs/inputs/DateTimeInput/index.js +34 -55
  75. package/cjs/inputs/DateTimeInput/index.js.map +2 -2
  76. package/cjs/inputs/FileInput/index.js +26 -45
  77. package/cjs/inputs/FileInput/index.js.map +2 -2
  78. package/cjs/inputs/ImageInput/index.js +10 -41
  79. package/cjs/inputs/ImageInput/index.js.map +2 -2
  80. package/cjs/inputs/Input/inputsInputScenarios/index.js +439 -0
  81. package/cjs/inputs/Input/inputsInputScenarios.js.map +7 -0
  82. package/cjs/lazy/index.js +6 -6
  83. package/cjs/lazy.js.map +2 -2
  84. package/cjs/registry/index.js +10 -8
  85. package/cjs/registry.js.map +2 -2
  86. package/cjs/validators/index.js +10 -8
  87. package/cjs/validators/index.js.map +2 -2
  88. package/cjs/validators/utils/date/index.js +3 -21
  89. package/cjs/validators/utils/date.js.map +2 -2
  90. package/cjs/validators/utils/datetime/index.js +24 -113
  91. package/cjs/validators/utils/datetime.js.map +2 -2
  92. package/index.js +1 -1
  93. package/inputs/AutoCompleteInput/AutoComplete.stories.d.ts +0 -2
  94. package/inputs/AutoCompleteInput/__stories__/Default.d.ts +1 -1
  95. package/inputs/AutoCompleteInput/__stories__/Multiple.d.ts +1 -1
  96. package/inputs/Checkboxes/Checkboxes.stories.d.ts +0 -2
  97. package/inputs/Checkboxes/__stories__/Conditional.d.ts +1 -1
  98. package/inputs/Checkboxes/__stories__/Default.d.ts +1 -1
  99. package/inputs/Checkboxes/__stories__/WithDivider.d.ts +1 -1
  100. package/inputs/Checkboxes/index.js +1 -2
  101. package/inputs/Checkboxes/index.js.map +2 -2
  102. package/inputs/DateInput/DateInput.stories.d.ts +0 -6
  103. package/inputs/DateInput/__stories__/Default.d.ts +1 -1
  104. package/inputs/DateInput/index.js +13 -28
  105. package/inputs/DateInput/index.js.map +2 -2
  106. package/inputs/DateTimeInput/DateTimeInput.stories.d.ts +3 -10
  107. package/inputs/DateTimeInput/__stories__/Default.d.ts +1 -1
  108. package/inputs/DateTimeInput/index.js +35 -56
  109. package/inputs/DateTimeInput/index.js.map +2 -2
  110. package/inputs/FileInput/FileInput.stories.d.ts +0 -2
  111. package/inputs/FileInput/__stories__/Default.d.ts +1 -1
  112. package/inputs/FileInput/index.d.ts +1 -5
  113. package/inputs/FileInput/index.js +27 -46
  114. package/inputs/FileInput/index.js.map +2 -2
  115. package/inputs/ImageInput/ImageInput.stories.d.ts +1 -4
  116. package/inputs/ImageInput/__stories__/Default.d.ts +1 -1
  117. package/inputs/ImageInput/__stories__/MaxSize.d.ts +1 -1
  118. package/inputs/ImageInput/__stories__/WithInvalidImageDimension.d.ts +1 -1
  119. package/inputs/ImageInput/index.d.ts +1 -9
  120. package/inputs/ImageInput/index.js +11 -42
  121. package/inputs/ImageInput/index.js.map +2 -2
  122. package/inputs/Input/Input.stories.d.ts +0 -3
  123. package/inputs/Input/__stories__/AFM.d.ts +1 -1
  124. package/inputs/Input/__stories__/Boolean.d.ts +1 -1
  125. package/inputs/Input/__stories__/IBAN.d.ts +1 -1
  126. package/inputs/Input/__stories__/Integer.d.ts +1 -1
  127. package/inputs/Input/__stories__/LandlineNumber.d.ts +1 -1
  128. package/inputs/Input/__stories__/MobilePhone.d.ts +1 -1
  129. package/inputs/Input/__stories__/PhoneNumber.d.ts +1 -1
  130. package/inputs/Input/__stories__/PostalCode.d.ts +1 -1
  131. package/inputs/Input/__stories__/String.d.ts +1 -1
  132. package/inputs/Input/__stories__/StringWithTrimValidation.d.ts +1 -1
  133. package/inputs/Input/__stories__/TextWithLimit.d.ts +1 -1
  134. package/inputs/Input/inputsInputScenarios/index.js +406 -0
  135. package/inputs/{ImageInput/__stories__/logo.d → Input/inputsInputScenarios}/package.json +1 -1
  136. package/inputs/Input/inputsInputScenarios.d.ts +57 -0
  137. package/inputs/Input/inputsInputScenarios.js.map +7 -0
  138. package/inputs/Label/Label.stories.d.ts +0 -2
  139. package/inputs/Label/__stories__/Default.d.ts +1 -1
  140. package/inputs/OtpInput/OtpInput.stories.d.ts +0 -2
  141. package/inputs/OtpInput/__stories__/Default.d.ts +1 -1
  142. package/inputs/Radio/Radio.stories.d.ts +0 -2
  143. package/inputs/Radio/__stories__/Conditional.d.ts +1 -1
  144. package/inputs/Radio/__stories__/Default.d.ts +1 -1
  145. package/inputs/Radio/__stories__/WithDivider.d.ts +1 -1
  146. package/inputs/Select/Select.stories.d.ts +0 -2
  147. package/inputs/Select/__stories__/Default.d.ts +1 -1
  148. package/lazy/index.js +6 -6
  149. package/package.json +8 -8
  150. package/registry/index.js +10 -8
  151. package/src/Field/FieldBase.tsx +18 -14
  152. package/src/Field/FieldBaseContainer.tsx +51 -68
  153. package/src/Field/FieldConditional.tsx +1 -1
  154. package/src/Field/index.tsx +1 -2
  155. package/src/Field/types.tsx +2 -2
  156. package/src/Field/utils/index.ts +1 -2
  157. package/src/FieldArray/FormDialog.tsx +12 -3
  158. package/src/FieldArray/__stories__/Default.tsx +1 -1
  159. package/src/FieldArray/__stories__/WithExactLength.tsx +1 -1
  160. package/src/FieldArray/__stories__/WithModal.tsx +1 -1
  161. package/src/FieldArray/index.tsx +103 -111
  162. package/src/FormBuilder/FormBuilder.stories.js +0 -3
  163. package/src/FormBuilder/__stories__/AutoErrorGrouping.tsx +1 -1
  164. package/src/FormBuilder/__stories__/Default.tsx +1 -1
  165. package/src/FormBuilder/__stories__/ErrorGrouping.tsx +1 -1
  166. package/src/FormBuilder/index.tsx +7 -3
  167. package/src/FormBuilder/scenarios.test.tsx +1 -1
  168. package/src/FormContext.tsx +1 -5
  169. package/src/MultiplicityField/MultiplicityField.stories.js +0 -3
  170. package/src/MultiplicityField/__stories__/Default.tsx +1 -1
  171. package/src/MultiplicityField/__stories__/PreviewDisplay.tsx +1 -1
  172. package/src/MultiplicityField/__stories__/WithExactLength.tsx +1 -1
  173. package/src/MultiplicityField/__stories__/WithMaxLength.tsx +1 -1
  174. package/src/MultiplicityField/__stories__/WithMinAndMaxLength.tsx +1 -1
  175. package/src/MultiplicityField/__stories__/WithMinLength.tsx +1 -1
  176. package/src/MultiplicityField/add-objects.tsx +1 -1
  177. package/src/MultiplicityField/index.tsx +1 -3
  178. package/src/MultiplicityField/types.ts +0 -1
  179. package/src/Questions/Questions.stories.js +0 -3
  180. package/src/Questions/__stories__/Default.tsx +1 -1
  181. package/src/inputs/AutoCompleteInput/AutoComplete.stories.js +0 -3
  182. package/src/inputs/AutoCompleteInput/__stories__/Default.tsx +1 -1
  183. package/src/inputs/AutoCompleteInput/__stories__/Multiple.tsx +1 -1
  184. package/src/inputs/Checkboxes/Checkboxes.stories.js +0 -3
  185. package/src/inputs/Checkboxes/__stories__/Conditional.tsx +1 -1
  186. package/src/inputs/Checkboxes/__stories__/Default.tsx +1 -1
  187. package/src/inputs/Checkboxes/__stories__/WithDivider.tsx +1 -1
  188. package/src/inputs/Checkboxes/index.tsx +5 -4
  189. package/src/inputs/DateInput/DateInput.stories.js +0 -7
  190. package/src/inputs/DateInput/__stories__/Default.tsx +1 -1
  191. package/src/inputs/DateInput/index.test.tsx +0 -16
  192. package/src/inputs/DateInput/index.tsx +13 -31
  193. package/src/inputs/DateTimeInput/DateTimeInput.stories.js +6 -12
  194. package/src/inputs/DateTimeInput/__stories__/Default.tsx +1 -1
  195. package/src/inputs/DateTimeInput/index.test.tsx +0 -16
  196. package/src/inputs/DateTimeInput/index.tsx +35 -59
  197. package/src/inputs/FileInput/FileInput.stories.js +0 -3
  198. package/src/inputs/FileInput/__stories__/Default.tsx +1 -1
  199. package/src/inputs/FileInput/index.tsx +39 -72
  200. package/src/inputs/ImageInput/ImageInput.stories.js +1 -5
  201. package/src/inputs/ImageInput/__stories__/Default.tsx +1 -1
  202. package/src/inputs/ImageInput/__stories__/MaxSize.tsx +2 -3
  203. package/src/inputs/ImageInput/__stories__/WithInvalidImageDimension.tsx +1 -1
  204. package/src/inputs/ImageInput/index.test.tsx +0 -4
  205. package/src/inputs/ImageInput/index.tsx +48 -100
  206. package/src/inputs/Input/Input.stories.js +0 -4
  207. package/src/inputs/Input/__stories__/AFM.tsx +1 -1
  208. package/src/inputs/Input/__stories__/Boolean.tsx +1 -1
  209. package/src/inputs/Input/__stories__/IBAN.tsx +1 -1
  210. package/src/inputs/Input/__stories__/Integer.tsx +1 -1
  211. package/src/inputs/Input/__stories__/LandlineNumber.tsx +1 -1
  212. package/src/inputs/Input/__stories__/MobilePhone.tsx +1 -1
  213. package/src/inputs/Input/__stories__/PhoneNumber.tsx +1 -1
  214. package/src/inputs/Input/__stories__/PostalCode.tsx +1 -1
  215. package/src/inputs/Input/__stories__/String.tsx +1 -1
  216. package/src/inputs/Input/__stories__/StringWithTrimValidation.tsx +1 -1
  217. package/src/inputs/Input/__stories__/TextWithLimit.tsx +1 -1
  218. package/src/inputs/Input/index.test.tsx +0 -8
  219. package/src/inputs/Input/inputsInputScenarios.ts +404 -0
  220. package/src/inputs/Label/Label.stories.js +0 -3
  221. package/src/inputs/Label/__stories__/Default.tsx +1 -1
  222. package/src/inputs/OtpInput/OtpInput.stories.js +0 -3
  223. package/src/inputs/OtpInput/__stories__/Default.tsx +1 -1
  224. package/src/inputs/Radio/Radio.stories.js +0 -3
  225. package/src/inputs/Radio/__stories__/Conditional.tsx +1 -1
  226. package/src/inputs/Radio/__stories__/Default.tsx +1 -1
  227. package/src/inputs/Radio/__stories__/WithDivider.tsx +1 -1
  228. package/src/inputs/Select/Select.stories.js +0 -3
  229. package/src/inputs/Select/__stories__/Default.tsx +1 -1
  230. package/src/lazy.js +6 -6
  231. package/src/registry.js +10 -8
  232. package/src/validators/index.ts +13 -13
  233. package/src/validators/utils/date.ts +4 -23
  234. package/src/validators/utils/datetime.ts +29 -116
  235. package/validators/index.js +10 -8
  236. package/validators/index.js.map +2 -2
  237. package/validators/utils/date/index.js +3 -21
  238. package/validators/utils/date.d.ts +1 -1
  239. package/validators/utils/date.js.map +2 -2
  240. package/validators/utils/datetime/index.js +24 -113
  241. package/validators/utils/datetime.d.ts +1 -1
  242. package/validators/utils/datetime.js.map +2 -2
  243. package/cjs/inputs/ImageInput/__stories__/logo.d/index.js +0 -1
  244. package/cjs/inputs/ImageInput/__stories__/logo.d.js.map +0 -7
  245. package/inputs/DateInput/__stories__/WithDefaultValue.d.ts +0 -3
  246. package/inputs/DateInput/__stories__/WithInitialValue.d.ts +0 -3
  247. package/inputs/DateInput/__stories__/WithWrongDefaultValue.d.ts +0 -3
  248. package/inputs/DateInput/__stories__/WithWrongInitialValue.d.ts +0 -3
  249. package/inputs/DateTimeInput/__stories__/WithDefaultValue.d.ts +0 -3
  250. package/inputs/DateTimeInput/__stories__/WithInitialValue.d.ts +0 -3
  251. package/inputs/DateTimeInput/__stories__/WithWrongDefaultValue.d.ts +0 -3
  252. package/inputs/DateTimeInput/__stories__/WithWrongInitialValue.d.ts +0 -3
  253. package/inputs/ImageInput/__stories__/WithInitialValues.d.ts +0 -3
  254. package/inputs/ImageInput/__stories__/logo.d/index.js +0 -1
  255. package/inputs/ImageInput/__stories__/logo.d.js.map +0 -7
  256. package/inputs/Input/__stories__/Email.d.ts +0 -3
  257. package/src/inputs/DateInput/__stories__/WithDefaultValue.tsx +0 -26
  258. package/src/inputs/DateInput/__stories__/WithInitialValue.tsx +0 -28
  259. package/src/inputs/DateInput/__stories__/WithWrongDefaultValue.tsx +0 -26
  260. package/src/inputs/DateInput/__stories__/WithWrongInitialValue.tsx +0 -28
  261. package/src/inputs/DateTimeInput/__stories__/WithDefaultValue.tsx +0 -26
  262. package/src/inputs/DateTimeInput/__stories__/WithInitialValue.tsx +0 -28
  263. package/src/inputs/DateTimeInput/__stories__/WithWrongDefaultValue.tsx +0 -26
  264. package/src/inputs/DateTimeInput/__stories__/WithWrongInitialValue.tsx +0 -28
  265. package/src/inputs/ImageInput/__stories__/WithInitialValues.tsx +0 -45
  266. package/src/inputs/ImageInput/__stories__/logo.d.ts +0 -4
  267. package/src/inputs/ImageInput/__stories__/logo.png +0 -0
  268. package/src/inputs/Input/__stories__/Email.tsx +0 -23
@@ -1,5 +1,10 @@
1
- import React, { useEffect, useRef } from 'react';
2
- import { ErrorOption, useFieldArray, UseFormReturn } from 'react-hook-form';
1
+ import React from 'react';
2
+ import {
3
+ Controller,
4
+ ErrorOption,
5
+ useFieldArray,
6
+ UseFormReturn,
7
+ } from 'react-hook-form';
3
8
  import { FieldBaseContainer } from '@digigov/form/Field/FieldBaseContainer';
4
9
  import { FieldProps } from '@digigov/form/Field/types';
5
10
  import { FormDialog } from '@digigov/form/FieldArray/FormDialog';
@@ -18,7 +23,7 @@ export interface FieldArrayProps extends FieldProps {
18
23
  getValues: UseFormReturn['getValues'];
19
24
  setValue: UseFormReturn['setValue'];
20
25
  reset: UseFormReturn['reset'];
21
- resetField?: UseFormReturn['resetField'];
26
+ resetField: UseFormReturn['resetField'];
22
27
  Field: React.FC<FieldProps>;
23
28
  }
24
29
  export const FieldArray: React.FC<FieldArrayProps> = ({
@@ -42,117 +47,104 @@ export const FieldArray: React.FC<FieldArrayProps> = ({
42
47
  control,
43
48
  name,
44
49
  });
45
- const fields = getValues(name) || [];
46
-
47
- /** The ref of the FieldBaseContainer. */
48
- const containerRef = useRef<HTMLFieldSetElement | null>(null);
49
-
50
- const { errors } = formState;
51
-
52
- // Focus the fieldset when there are errors related to this field array
53
- useEffect(() => {
54
- if (!containerRef.current) return;
55
- const fieldErrors = Object.keys(errors);
56
- // no errors
57
- if (!fieldErrors.length) return;
58
-
59
- if (
60
- // Check if there are errors related to the current field array
61
- fieldErrors.some((key) => {
62
- const fieldArrayName = key.split('.')[0];
63
- return fieldArrayName === name;
64
- })
65
- ) {
66
- if (containerRef.current && errors[name]) {
67
- containerRef.current.focus();
68
- }
69
- }
70
- }, [errors, name]);
71
50
 
51
+ const fields = getValues(name) || [];
72
52
  return (
73
- <FieldBaseContainer
74
- label={label}
75
- layout={layout}
76
- register={register}
77
- ref={containerRef}
78
- error={error?.message && error ? error : undefined}
79
- hasError={formState.isSubmitted && !formState.isSubmitting && !!error}
80
- wrapper="fieldset"
53
+ <Controller
54
+ render={({ field }) => {
55
+ return (
56
+ <FieldBaseContainer
57
+ label={label}
58
+ layout={layout}
59
+ register={register}
60
+ error={error?.message && error ? error : undefined}
61
+ hasError={
62
+ formState.isSubmitted && !formState.isSubmitting && !!error
63
+ }
64
+ wrapper="fieldset"
65
+ name={name}
66
+ labelSize={customField.extra?.labelSize}
67
+ >
68
+ <div tabIndex={-1} ref={field.ref} />
69
+
70
+ {customField.extra?.variant === 'dialog' ? (
71
+ <FormDialog
72
+ name={name}
73
+ trigger={trigger}
74
+ register={register}
75
+ clearErrors={clearErrors}
76
+ control={control}
77
+ formState={formState}
78
+ error={error}
79
+ getValues={getValues}
80
+ setValue={setValue}
81
+ layout={layout}
82
+ label={label}
83
+ Field={Field}
84
+ reset={reset}
85
+ resetField={resetField}
86
+ sortable={customField.extra.sortable}
87
+ {...customField}
88
+ />
89
+ ) : (
90
+ <>
91
+ {fields.map((field, index) => (
92
+ <Card
93
+ variant={customField.extra?.border ? 'border' : 'divider'}
94
+ key={field.id}
95
+ >
96
+ <Fieldset>
97
+ <FieldsetLabel>
98
+ {customField.extra?.label.object.title}{' '}
99
+ {!customField.extra?.noIndex && index + 1}
100
+ </FieldsetLabel>
101
+ <FieldObject
102
+ name={`${name}.${index}`}
103
+ error={Array.isArray(error) && error[index]}
104
+ formState={formState}
105
+ register={register}
106
+ control={control}
107
+ {...customField.extra?.of}
108
+ Field={Field}
109
+ />
110
+ <Button
111
+ name={`${name}-object-remove`}
112
+ variant={
113
+ customField.extra?.label.object?.deleteButtonVariant
114
+ }
115
+ type="button"
116
+ color="warning"
117
+ onClick={() => remove(index)}
118
+ disabled={!customField?.editable}
119
+ >
120
+ {customField.extra?.label.object?.delete}
121
+ </Button>
122
+ </Fieldset>
123
+ </Card>
124
+ ))}
125
+ {customField.editable && (
126
+ <Button
127
+ type="button"
128
+ name={`${name}-add-object`}
129
+ color="secondary"
130
+ variant={customField.extra?.label.object?.addButtonVariant}
131
+ onClick={(ev) => {
132
+ ev.preventDefault();
133
+ append({});
134
+ }}
135
+ disabled={!customField?.editable}
136
+ >
137
+ {customField.extra?.label.object?.add}
138
+ </Button>
139
+ )}
140
+ </>
141
+ )}
142
+ </FieldBaseContainer>
143
+ );
144
+ }}
145
+ control={control}
81
146
  name={name}
82
- labelSize={customField.extra?.labelSize}
83
- controlled={true}
84
- >
85
- {customField.extra?.variant === 'dialog' ? (
86
- <FormDialog
87
- name={name}
88
- trigger={trigger}
89
- register={register}
90
- clearErrors={clearErrors}
91
- control={control}
92
- formState={formState}
93
- error={error}
94
- getValues={getValues}
95
- setValue={setValue}
96
- layout={layout}
97
- label={label}
98
- Field={Field}
99
- reset={reset}
100
- resetField={resetField}
101
- sortable={customField.extra.sortable}
102
- {...customField}
103
- />
104
- ) : (
105
- <>
106
- {fields.map((field, index) => (
107
- <Card
108
- variant={customField.extra?.border ? 'border' : 'divider'}
109
- key={field.id || index}
110
- >
111
- <Fieldset>
112
- <FieldsetLabel>
113
- {customField.extra?.label.object.title}{' '}
114
- {!customField.extra?.noIndex && index + 1}
115
- </FieldsetLabel>
116
- <FieldObject
117
- name={`${name}.${index}`}
118
- error={Array.isArray(error) && error[index]}
119
- formState={formState}
120
- register={register}
121
- control={control}
122
- {...customField.extra?.of}
123
- Field={Field}
124
- />
125
- <Button
126
- name={`${name}-object-remove`}
127
- variant={customField.extra?.label.object?.deleteButtonVariant}
128
- type="button"
129
- color="warning"
130
- onClick={() => remove(index)}
131
- disabled={!customField?.editable}
132
- >
133
- {customField.extra?.label.object?.delete}
134
- </Button>
135
- </Fieldset>
136
- </Card>
137
- ))}
138
- {customField.editable && (
139
- <Button
140
- type="button"
141
- name={`${name}-add-object`}
142
- color="secondary"
143
- variant={customField.extra?.label.object?.addButtonVariant}
144
- onClick={(ev) => {
145
- ev.preventDefault();
146
- append({});
147
- }}
148
- disabled={!customField?.editable}
149
- >
150
- {customField.extra?.label.object?.add}
151
- </Button>
152
- )}
153
- </>
154
- )}
155
- </FieldBaseContainer>
147
+ />
156
148
  );
157
149
  };
158
150
 
@@ -1,10 +1,7 @@
1
1
  import FormBuilder from '@digigov/form/FormBuilder';
2
- import doc from './doc.mdx?raw';
3
2
  export default {
4
3
  title: 'Digigov Form/FormBuilder',
5
4
  component: FormBuilder,
6
- tags: ['autodocs'],
7
- markdown: doc,
8
5
  displayName: 'FormBuilder',
9
6
  };
10
7
  export { Default } from '@digigov/form/FormBuilder/__stories__/Default';
@@ -49,7 +49,7 @@ const FIELDS: FieldSpec[] = [
49
49
  },
50
50
  ];
51
51
 
52
- export const AutoErrorGrouping = (_: any) => (
52
+ export const AutoErrorGrouping = () => (
53
53
  <FormBuilder
54
54
  grid={true}
55
55
  auto={true}
@@ -6,7 +6,7 @@ const initialValues = {
6
6
  'business-title': null,
7
7
  };
8
8
 
9
- export const Default = (_: any) => (
9
+ export const Default = () => (
10
10
  <FormBuilder
11
11
  onSubmit={(data) => {
12
12
  console.log(data);
@@ -3,7 +3,7 @@ import FormBuilder, { Field } from '@digigov/form';
3
3
  import { ErrorGroup } from '@digigov/form/Field/ErrorGroup';
4
4
  import { Button } from '@digigov/ui/form/Button';
5
5
 
6
- export const ErrorGrouping = (_: any) => (
6
+ export const ErrorGrouping = () => (
7
7
  <FormBuilder
8
8
  grid={true}
9
9
  onSubmit={(data) => {
@@ -1,10 +1,10 @@
1
- import React, { useCallback, useEffect, useRef } from 'react';
1
+ import React, { useCallback, useContext, useEffect, useRef } from 'react';
2
2
  import { useForm } from 'react-hook-form';
3
3
  import { Field } from '@digigov/form/Field';
4
4
  import { ErrorGroup } from '@digigov/form/Field/ErrorGroup';
5
5
  import { CONTROLLED_FIELD_COMPONENTS } from '@digigov/form/Field/utils';
6
6
  import { FieldsetWithContext } from '@digigov/form/Fieldset/FieldsetWithContext';
7
- import { FormContext, useFormContext } from '@digigov/form/FormContext';
7
+ import { FormContext } from '@digigov/form/FormContext';
8
8
  import { FormBaseProps, FormData, FormBuilderProps } from '@digigov/form/types';
9
9
  import { yupResolver } from '@digigov/form/utils';
10
10
  import { useValidationSchema } from '@digigov/form/validators';
@@ -44,6 +44,7 @@ const FormBase = React.forwardRef(function FormBase(
44
44
  const handleSubmit = useCallback(
45
45
  (data: FormData): void => {
46
46
  if (onSubmit) {
47
+ form.reset(data);
47
48
  onSubmit(data);
48
49
  }
49
50
  },
@@ -52,7 +53,7 @@ const FormBase = React.forwardRef(function FormBase(
52
53
  useEffect(() => {
53
54
  if (errors) {
54
55
  for (const fieldName in errors) {
55
- form.setError(fieldName, errors[fieldName]);
56
+ form.setError(fieldName, errors[fieldName], { shouldFocus: true });
56
57
  }
57
58
  }
58
59
  }, [errors]);
@@ -126,6 +127,9 @@ const groupFieldsByLayout = (fields) => {
126
127
  return sizes;
127
128
  }, {});
128
129
  };
130
+ const useFormContext = () => {
131
+ return useContext(FormContext);
132
+ };
129
133
  const useFormValues = () => {
130
134
  const ctx = useFormContext();
131
135
  return ctx.getValues();
@@ -1564,7 +1564,7 @@ const inputsInputScenarios = [
1564
1564
  },
1565
1565
  {
1566
1566
  fieldKey: 'email',
1567
- value: 'example@mail.',
1567
+ value: '23232',
1568
1568
  },
1569
1569
  {
1570
1570
  fieldKey: 'location',
@@ -1,11 +1,7 @@
1
- import React, { createContext, useContext } from 'react';
1
+ import React, { createContext } from 'react';
2
2
  import { FormContextProps } from '@digigov/form/types';
3
3
 
4
4
  export const FormContext: React.Context<FormContextProps> = createContext({
5
5
  fieldsMap: {},
6
6
  fieldsetsMap: {},
7
7
  } as FormContextProps);
8
-
9
- export const useFormContext = () => {
10
- return useContext(FormContext);
11
- };
@@ -1,10 +1,7 @@
1
1
  import MultiplicityField from '@digigov/form/MultiplicityField';
2
- import doc from './doc.mdx?raw';
3
2
  export default {
4
3
  title: 'Digigov Form/MultiplicityField',
5
4
  component: MultiplicityField,
6
- tags: ['autodocs'],
7
- markdown: doc,
8
5
  displayName: 'MultiplicityField',
9
6
  };
10
7
  export { Default } from '@digigov/form/MultiplicityField/__stories__/Default';
@@ -85,7 +85,7 @@ const fields = [
85
85
  },
86
86
  ] as FieldSpec[];
87
87
 
88
- export const Default = (_: any) => (
88
+ export const Default = () => (
89
89
  <FormBuilder
90
90
  onSubmit={(data) => {
91
91
  console.log(data);
@@ -61,7 +61,7 @@ const fields = [
61
61
  },
62
62
  ];
63
63
 
64
- export const PreviewDisplay = (_: any) => (
64
+ export const PreviewDisplay = () => (
65
65
  <Layout>
66
66
  <Header>
67
67
  <HeaderContent>
@@ -84,7 +84,7 @@ const fields = [
84
84
  },
85
85
  ] as FieldSpec[];
86
86
 
87
- export const WithExactLength = (_: any) => (
87
+ export const WithExactLength = () => (
88
88
  <FormBuilder
89
89
  onSubmit={(data) => {
90
90
  console.log(data);
@@ -87,7 +87,7 @@ const fields = [
87
87
  },
88
88
  ] as FieldSpec[];
89
89
 
90
- export const WithMaxLength = (_: any) => (
90
+ export const WithMaxLength = () => (
91
91
  <FormBuilder
92
92
  onSubmit={(data) => {
93
93
  console.log(data);
@@ -88,7 +88,7 @@ const fields = [
88
88
  },
89
89
  ] as FieldSpec[];
90
90
 
91
- export const WithMinAndMaxLength = (_: any) => (
91
+ export const WithMinAndMaxLength = () => (
92
92
  <FormBuilder
93
93
  onSubmit={(data) => {
94
94
  console.log(data);
@@ -87,7 +87,7 @@ const fields = [
87
87
  },
88
88
  ] as FieldSpec[];
89
89
 
90
- export const WithMinLength = (_: any) => (
90
+ export const WithMinLength = () => (
91
91
  <FormBuilder
92
92
  onSubmit={(data) => {
93
93
  console.log(data);
@@ -47,7 +47,6 @@ export const AddObjects: React.FC<AddObjectsProps> = ({
47
47
  setValue,
48
48
  stashedObjects,
49
49
  getValues,
50
- resetField,
51
50
  onStash,
52
51
  error,
53
52
  Field,
@@ -134,6 +133,7 @@ export const AddObjects: React.FC<AddObjectsProps> = ({
134
133
  control,
135
134
  register,
136
135
  reset,
136
+ resetField,
137
137
  error: needsMoreError,
138
138
  } = useField(radioField.key, radioField?.type ? radioField : null);
139
139
 
@@ -31,7 +31,6 @@ export const Multiplicity: React.FC<MultiplicityProps> = ({
31
31
  setValue,
32
32
  getValues,
33
33
  unregister,
34
- resetField,
35
34
  Field,
36
35
  }) => {
37
36
  const { fields, append, remove } = useFieldArray({
@@ -53,6 +52,7 @@ export const Multiplicity: React.FC<MultiplicityProps> = ({
53
52
  <FieldBaseContainer
54
53
  label={label}
55
54
  layout={layout}
55
+ register={register}
56
56
  error={
57
57
  formState.isSubmitted && !formState.isSubmitting && error?.message
58
58
  ? error
@@ -61,7 +61,6 @@ export const Multiplicity: React.FC<MultiplicityProps> = ({
61
61
  hasError={formState.isSubmitted && !formState.isSubmitting && !!error}
62
62
  wrapper="fieldset"
63
63
  name={name}
64
- register={register}
65
64
  >
66
65
  {stashedObjects.length > 0 ? (
67
66
  <div>
@@ -100,7 +99,6 @@ export const Multiplicity: React.FC<MultiplicityProps> = ({
100
99
  getValues={getValues}
101
100
  unregister={unregister}
102
101
  trigger={trigger}
103
- resetField={resetField}
104
102
  clearErrors={clearErrors}
105
103
  Field={Field}
106
104
  />
@@ -12,7 +12,6 @@ export interface MultiplicityProps
12
12
  setValue: UseFormReturn['setValue'];
13
13
  getValues: UseFormReturn['getValues'];
14
14
  unregister: UseFormReturn['unregister'];
15
- resetField?: UseFormReturn['resetField'];
16
15
  error?: ErrorOption;
17
16
  extra?: Record<string, any>;
18
17
  label?: FieldSpec['label'];
@@ -1,10 +1,7 @@
1
1
  import Questions from '@digigov/form/Questions';
2
- import doc from './doc.mdx?raw';
3
2
  export default {
4
3
  title: 'Digigov Form/Questions',
5
4
  component: Questions,
6
- tags: ['autodocs'],
7
- markdown: doc,
8
5
  displayName: 'Questions',
9
6
  };
10
7
  export { Default } from '@digigov/form/Questions/__stories__/Default';
@@ -75,7 +75,7 @@ const steps = [
75
75
  },
76
76
  ];
77
77
 
78
- export function Default(_: any) {
78
+ export function Default() {
79
79
  return (
80
80
  <BasicLayout>
81
81
  <Top>
@@ -1,10 +1,7 @@
1
1
  import AutoComplete from '@digigov/form/inputs/AutoCompleteInput';
2
- import doc from './doc.mdx?raw';
3
2
  export default {
4
3
  title: 'Digigov Form/inputs/AutoCompleteInput',
5
4
  component: AutoComplete,
6
- tags: ['autodocs'],
7
- markdown: doc,
8
5
  displayName: 'AutoCompleteInput',
9
6
  };
10
7
  export { Default } from '@digigov/form/inputs/AutoCompleteInput/__stories__/Default';
@@ -29,7 +29,7 @@ const fields: FieldSpec[] = [
29
29
 
30
30
  const initialValues = {};
31
31
 
32
- export const Default = (_: any) => (
32
+ export const Default = () => (
33
33
  <FormBuilder
34
34
  fields={fields}
35
35
  onSubmit={(data) => {
@@ -29,7 +29,7 @@ const fields: FieldSpec[] = [
29
29
 
30
30
  const initialValues = {};
31
31
 
32
- export const Multiple = (_: any) => (
32
+ export const Multiple = () => (
33
33
  <FormBuilder
34
34
  fields={fields}
35
35
  onSubmit={(data) => {
@@ -1,10 +1,7 @@
1
1
  import Checkboxes from '@digigov/form/inputs/Checkboxes';
2
- import doc from './doc.mdx?raw';
3
2
  export default {
4
3
  title: 'Digigov Form/inputs/Checkboxes',
5
4
  component: Checkboxes,
6
- tags: ['autodocs'],
7
- markdown: doc,
8
5
  displayName: 'Checkboxes',
9
6
  };
10
7
  export { Default } from '@digigov/form/inputs/Checkboxes/__stories__/Default';
@@ -84,7 +84,7 @@ const fields: FieldSpec[] = [
84
84
  },
85
85
  ];
86
86
 
87
- export const Conditional = (_: any) => (
87
+ export const Conditional = () => (
88
88
  <FormBuilder
89
89
  onSubmit={(data) => {
90
90
  console.log(data);
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import FormBuilder, { Field } from '@digigov/form';
3
3
  import { Button } from '@digigov/ui/form/Button';
4
4
 
5
- export const Default = (_: any) => (
5
+ export const Default = () => (
6
6
  <FormBuilder
7
7
  onSubmit={(data) => {
8
8
  console.log(data);
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import FormBuilder, { Field } from '@digigov/form';
3
3
  import { Button } from '@digigov/ui/form/Button';
4
4
 
5
- export const WithDivider = (_: any) => (
5
+ export const WithDivider = () => (
6
6
  <FormBuilder
7
7
  onSubmit={(data) => {
8
8
  console.log(data);
@@ -32,10 +32,14 @@ export const Checkboxes: React.FC<CheckboxesProps> = ({
32
32
  const handleChange =
33
33
  (optionValue, idx, show) =>
34
34
  (evt): void => {
35
- let newValue: any = [];
35
+ let newValue;
36
36
  if (evt.currentTarget.checked) {
37
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
38
+ // @ts-ignore
37
39
  newValue = value.concat([optionValue]);
38
40
  } else {
41
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
42
+ // @ts-ignore
39
43
  newValue = value.filter((val) => val !== optionValue);
40
44
  }
41
45
  if (show && show.length > 0) {
@@ -44,9 +48,6 @@ export const Checkboxes: React.FC<CheckboxesProps> = ({
44
48
  );
45
49
  }
46
50
 
47
- // reset value to undefined instead of an empty array
48
- // so the error state mechanism can throw validation errors
49
- if (newValue.length === 0) newValue = undefined;
50
51
  onChange(newValue);
51
52
  };
52
53
  const { t } = useTranslation();
@@ -1,14 +1,7 @@
1
1
  import DateInput from '@digigov/form/inputs/DateInput';
2
- import doc from './doc.mdx?raw';
3
2
  export default {
4
3
  title: 'Digigov Form/inputs/DateInput',
5
4
  component: DateInput,
6
- tags: ['autodocs'],
7
- markdown: doc,
8
5
  displayName: 'DateInput',
9
6
  };
10
7
  export { Default } from '@digigov/form/inputs/DateInput/__stories__/Default';
11
- export { WithDefaultValue } from '@digigov/form/inputs/DateInput/__stories__/WithDefaultValue';
12
- export { WithWrongDefaultValue } from '@digigov/form/inputs/DateInput/__stories__/WithWrongDefaultValue';
13
- export { WithInitialValue } from '@digigov/form/inputs/DateInput/__stories__/WithInitialValue';
14
- export { WithWrongInitialValue } from '@digigov/form/inputs/DateInput/__stories__/WithWrongInitialValue';
@@ -14,7 +14,7 @@ const fields = [
14
14
  } as const,
15
15
  ];
16
16
 
17
- export const Default = (_: any) => (
17
+ export const Default = () => (
18
18
  <FormBuilder onSubmit={() => console.log('kati')}>
19
19
  {fields.map(({ key, ...field }) => {
20
20
  return <Field {...field} name={key} key={key} />;
@@ -2,10 +2,6 @@ import React from 'react';
2
2
  import { test, expect } from '@playwright/experimental-ct-react';
3
3
  import TestVariant from '@digigov/ui/utils/TestVariant'
4
4
  import { Default } from '@digigov/form/inputs/DateInput/__stories__/Default';
5
- import { WithDefaultValue } from '@digigov/form/inputs/DateInput/__stories__/WithDefaultValue';
6
- import { WithInitialValue } from '@digigov/form/inputs/DateInput/__stories__/WithInitialValue';
7
- import { WithWrongDefaultValue } from '@digigov/form/inputs/DateInput/__stories__/WithWrongDefaultValue';
8
- import { WithWrongInitialValue } from '@digigov/form/inputs/DateInput/__stories__/WithWrongInitialValue';
9
5
 
10
6
  test('renders the All DateInput variants', async ({ mount, page }) => {
11
7
  await mount(
@@ -14,18 +10,6 @@ test('renders the All DateInput variants', async ({ mount, page }) => {
14
10
  <TestVariant title="Default">
15
11
  <Default />
16
12
  </TestVariant>
17
- <TestVariant title="WithDefaultValue">
18
- <WithDefaultValue />
19
- </TestVariant>
20
- <TestVariant title="WithInitialValue">
21
- <WithInitialValue />
22
- </TestVariant>
23
- <TestVariant title="WithWrongDefaultValue">
24
- <WithWrongDefaultValue />
25
- </TestVariant>
26
- <TestVariant title="WithWrongInitialValue">
27
- <WithWrongInitialValue />
28
- </TestVariant>
29
13
  </div>
30
14
  )
31
15
  await page.evaluate(() => document.fonts.ready);