@digigov/form 2.0.0-a32ad9b2 → 2.0.0-a402a664

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 (300) hide show
  1. package/Field/FieldBase/index.js +6 -1
  2. package/Field/FieldBase.js.map +2 -2
  3. package/Field/FieldBaseContainer/index.js +5 -3
  4. package/Field/FieldBaseContainer.js.map +2 -2
  5. package/Field/FieldConditional/index.js +4 -0
  6. package/Field/FieldConditional.js.map +2 -2
  7. package/Field/index.js +10 -4
  8. package/Field/index.js.map +2 -2
  9. package/Field/types.d.ts +10 -3
  10. package/Field/utils/index.js +3 -1
  11. package/Field/utils/index.js.map +2 -2
  12. package/Field/utils/useField/index.js +8 -1
  13. package/Field/utils/useField.js.map +2 -2
  14. package/FieldArray/FormDialog/index.js +314 -196
  15. package/FieldArray/FormDialog.d.ts +20 -7
  16. package/FieldArray/FormDialog.js.map +3 -3
  17. package/FieldArray/__stories__/Default.d.ts +1 -1
  18. package/FieldArray/__stories__/WithExactLength.d.ts +1 -1
  19. package/FieldArray/__stories__/WithModal.d.ts +1 -1
  20. package/FieldArray/index.d.ts +1 -0
  21. package/FieldArray/index.js +12 -7
  22. package/FieldArray/index.js.map +2 -2
  23. package/FieldObject/index.d.ts +3 -0
  24. package/FieldObject/index.js +26 -15
  25. package/FieldObject/index.js.map +2 -2
  26. package/FormBuilder/FormBuilder.stories.d.ts +2 -0
  27. package/FormBuilder/__stories__/AutoErrorGrouping.d.ts +1 -1
  28. package/FormBuilder/__stories__/Default.d.ts +1 -1
  29. package/FormBuilder/__stories__/ErrorGrouping.d.ts +1 -1
  30. package/FormBuilder/index.d.ts +1 -1
  31. package/FormBuilder/index.js +11 -6
  32. package/FormBuilder/index.js.map +2 -2
  33. package/FormContext/index.js +6 -2
  34. package/FormContext.d.ts +1 -0
  35. package/FormContext.js.map +2 -2
  36. package/MultiplicityField/MultiplicityField.stories.d.ts +2 -0
  37. package/MultiplicityField/__stories__/Default.d.ts +1 -1
  38. package/MultiplicityField/__stories__/PreviewDisplay.d.ts +1 -1
  39. package/MultiplicityField/__stories__/WithExactLength.d.ts +1 -1
  40. package/MultiplicityField/__stories__/WithMaxLength.d.ts +1 -1
  41. package/MultiplicityField/__stories__/WithMinAndMaxLength.d.ts +1 -1
  42. package/MultiplicityField/__stories__/WithMinLength.d.ts +1 -1
  43. package/MultiplicityField/add-objects/index.js +2 -0
  44. package/MultiplicityField/add-objects.js.map +2 -2
  45. package/MultiplicityField/index.js +4 -1
  46. package/MultiplicityField/index.js.map +2 -2
  47. package/MultiplicityField/types.d.ts +1 -0
  48. package/Questions/Questions.stories.d.ts +2 -0
  49. package/Questions/__stories__/Default.d.ts +1 -1
  50. package/cjs/Field/FieldBase/index.js +6 -1
  51. package/cjs/Field/FieldBase.js.map +2 -2
  52. package/cjs/Field/FieldBaseContainer/index.js +4 -2
  53. package/cjs/Field/FieldBaseContainer.js.map +3 -3
  54. package/cjs/Field/FieldConditional/index.js +4 -0
  55. package/cjs/Field/FieldConditional.js.map +2 -2
  56. package/cjs/Field/index.js +10 -4
  57. package/cjs/Field/index.js.map +2 -2
  58. package/cjs/Field/types.js.map +1 -1
  59. package/cjs/Field/utils/index.js +3 -1
  60. package/cjs/Field/utils/index.js.map +2 -2
  61. package/cjs/Field/utils/useField/index.js +8 -1
  62. package/cjs/Field/utils/useField.js.map +2 -2
  63. package/cjs/FieldArray/FormDialog/index.js +309 -194
  64. package/cjs/FieldArray/FormDialog.js.map +3 -3
  65. package/cjs/FieldArray/index.js +12 -7
  66. package/cjs/FieldArray/index.js.map +2 -2
  67. package/cjs/FieldObject/index.js +26 -15
  68. package/cjs/FieldObject/index.js.map +2 -2
  69. package/cjs/FormBuilder/index.js +11 -6
  70. package/cjs/FormBuilder/index.js.map +2 -2
  71. package/cjs/FormContext/index.js +7 -2
  72. package/cjs/FormContext.js.map +2 -2
  73. package/cjs/MultiplicityField/add-objects/index.js +2 -0
  74. package/cjs/MultiplicityField/add-objects.js.map +2 -2
  75. package/cjs/MultiplicityField/index.js +4 -1
  76. package/cjs/MultiplicityField/index.js.map +2 -2
  77. package/cjs/MultiplicityField/types.js.map +1 -1
  78. package/cjs/inputs/Checkboxes/index.js +1 -1
  79. package/cjs/inputs/Checkboxes/index.js.map +2 -2
  80. package/cjs/inputs/DateInput/index.js +20 -8
  81. package/cjs/inputs/DateInput/index.js.map +2 -2
  82. package/cjs/inputs/DateTimeInput/index.js +23 -10
  83. package/cjs/inputs/DateTimeInput/index.js.map +2 -2
  84. package/cjs/inputs/FileInput/index.js +26 -21
  85. package/cjs/inputs/FileInput/index.js.map +2 -2
  86. package/cjs/inputs/ImageInput/__stories__/logo.d/index.js +1 -0
  87. package/cjs/inputs/ImageInput/__stories__/logo.d.js.map +7 -0
  88. package/cjs/inputs/ImageInput/index.js +41 -10
  89. package/cjs/inputs/ImageInput/index.js.map +2 -2
  90. package/cjs/inputs/Input/index.js +4 -4
  91. package/cjs/inputs/Input/index.js.map +2 -2
  92. package/cjs/inputs/Select/index.js +4 -3
  93. package/cjs/inputs/Select/index.js.map +2 -2
  94. package/cjs/inputs/inputsScenarios/index.js +2 -2
  95. package/cjs/inputs/inputsScenarios.js.map +2 -2
  96. package/cjs/lazy/index.js +2 -1
  97. package/cjs/lazy.js.map +2 -2
  98. package/cjs/registry/index.js +6 -6
  99. package/cjs/registry.js.map +2 -2
  100. package/cjs/types.js.map +1 -1
  101. package/cjs/utils/index.js +20 -6
  102. package/cjs/utils.js.map +2 -2
  103. package/cjs/validators/index.js +10 -5
  104. package/cjs/validators/index.js.map +2 -2
  105. package/cjs/validators/utils/amka/index.js +60 -0
  106. package/cjs/validators/utils/amka.js.map +7 -0
  107. package/cjs/validators/utils/file/index.js +30 -17
  108. package/cjs/validators/utils/file.js.map +2 -2
  109. package/cjs/validators/utils/index.js +5 -1
  110. package/cjs/validators/utils/index.js.map +2 -2
  111. package/index.js +1 -1
  112. package/inputs/AutoCompleteInput/AutoComplete.stories.d.ts +2 -0
  113. package/inputs/AutoCompleteInput/__stories__/Default.d.ts +1 -1
  114. package/inputs/AutoCompleteInput/__stories__/Multiple.d.ts +1 -1
  115. package/inputs/Checkboxes/Checkboxes.stories.d.ts +2 -0
  116. package/inputs/Checkboxes/__stories__/Conditional.d.ts +1 -1
  117. package/inputs/Checkboxes/__stories__/Default.d.ts +1 -1
  118. package/inputs/Checkboxes/__stories__/WithDivider.d.ts +1 -1
  119. package/inputs/Checkboxes/index.js +1 -1
  120. package/inputs/Checkboxes/index.js.map +2 -2
  121. package/inputs/DateInput/DateInput.stories.d.ts +2 -0
  122. package/inputs/DateInput/__stories__/Default.d.ts +1 -1
  123. package/inputs/DateInput/index.js +20 -8
  124. package/inputs/DateInput/index.js.map +2 -2
  125. package/inputs/DateTimeInput/DateTimeInput.stories.d.ts +2 -0
  126. package/inputs/DateTimeInput/__stories__/Default.d.ts +1 -1
  127. package/inputs/DateTimeInput/index.js +23 -10
  128. package/inputs/DateTimeInput/index.js.map +2 -2
  129. package/inputs/FileInput/FileInput.stories.d.ts +3 -0
  130. package/inputs/FileInput/__stories__/Default.d.ts +1 -1
  131. package/inputs/FileInput/__stories__/WithBorderAndLink.d.ts +3 -0
  132. package/inputs/FileInput/index.d.ts +6 -3
  133. package/inputs/FileInput/index.js +31 -23
  134. package/inputs/FileInput/index.js.map +2 -2
  135. package/inputs/ImageInput/ImageInput.stories.d.ts +4 -1
  136. package/inputs/ImageInput/__stories__/Default.d.ts +1 -1
  137. package/inputs/ImageInput/__stories__/MaxSize.d.ts +1 -1
  138. package/inputs/ImageInput/__stories__/WithInitialValues.d.ts +3 -0
  139. package/inputs/ImageInput/__stories__/WithInvalidImageDimension.d.ts +1 -1
  140. package/inputs/ImageInput/__stories__/logo.d/index.js +1 -0
  141. package/inputs/ImageInput/__stories__/logo.d/package.json +6 -0
  142. package/inputs/ImageInput/__stories__/logo.d.js.map +7 -0
  143. package/inputs/ImageInput/index.d.ts +9 -1
  144. package/inputs/ImageInput/index.js +42 -11
  145. package/inputs/ImageInput/index.js.map +2 -2
  146. package/inputs/Input/Input.stories.d.ts +4 -0
  147. package/inputs/Input/__stories__/AFM.d.ts +1 -1
  148. package/inputs/Input/__stories__/AMKA.d.ts +3 -0
  149. package/inputs/Input/__stories__/Boolean.d.ts +1 -1
  150. package/inputs/Input/__stories__/Email.d.ts +3 -0
  151. package/inputs/Input/__stories__/IBAN.d.ts +1 -1
  152. package/inputs/Input/__stories__/Integer.d.ts +1 -1
  153. package/inputs/Input/__stories__/LandlineNumber.d.ts +1 -1
  154. package/inputs/Input/__stories__/MobilePhone.d.ts +1 -1
  155. package/inputs/Input/__stories__/PhoneNumber.d.ts +1 -1
  156. package/inputs/Input/__stories__/PostalCode.d.ts +1 -1
  157. package/inputs/Input/__stories__/String.d.ts +1 -1
  158. package/inputs/Input/__stories__/StringWithTrimValidation.d.ts +1 -1
  159. package/inputs/Input/__stories__/TextWithLimit.d.ts +1 -1
  160. package/inputs/Input/index.d.ts +2 -1
  161. package/inputs/Input/index.js +4 -4
  162. package/inputs/Input/index.js.map +2 -2
  163. package/inputs/Label/Label.stories.d.ts +2 -0
  164. package/inputs/Label/__stories__/Default.d.ts +1 -1
  165. package/inputs/OtpInput/OtpInput.stories.d.ts +2 -0
  166. package/inputs/OtpInput/__stories__/Default.d.ts +1 -1
  167. package/inputs/Radio/Radio.stories.d.ts +2 -0
  168. package/inputs/Radio/__stories__/Conditional.d.ts +1 -1
  169. package/inputs/Radio/__stories__/Default.d.ts +1 -1
  170. package/inputs/Radio/__stories__/WithDivider.d.ts +1 -1
  171. package/inputs/Select/Select.stories.d.ts +2 -0
  172. package/inputs/Select/__stories__/Default.d.ts +1 -1
  173. package/inputs/Select/index.d.ts +2 -1
  174. package/inputs/Select/index.js +4 -3
  175. package/inputs/Select/index.js.map +2 -2
  176. package/inputs/inputsScenarios/index.js +2 -2
  177. package/inputs/inputsScenarios.d.ts +1 -1
  178. package/inputs/inputsScenarios.js.map +2 -2
  179. package/lazy/index.js +2 -1
  180. package/package.json +4 -4
  181. package/registry/index.js +6 -6
  182. package/src/Field/FieldBase.tsx +5 -0
  183. package/src/Field/FieldBaseContainer.tsx +8 -4
  184. package/src/Field/FieldConditional.tsx +4 -0
  185. package/src/Field/index.tsx +15 -5
  186. package/src/Field/types.tsx +11 -3
  187. package/src/Field/utils/index.ts +2 -0
  188. package/src/Field/utils/useField.ts +9 -1
  189. package/src/FieldArray/FormDialog.tsx +430 -243
  190. package/src/FieldArray/__stories__/Default.tsx +1 -1
  191. package/src/FieldArray/__stories__/WithExactLength.tsx +1 -1
  192. package/src/FieldArray/__stories__/WithModal.tsx +4 -3
  193. package/src/FieldArray/index.tsx +26 -30
  194. package/src/FieldObject/index.tsx +33 -18
  195. package/src/FormBuilder/FormBuilder.stories.js +3 -0
  196. package/src/FormBuilder/__stories__/AutoErrorGrouping.tsx +1 -1
  197. package/src/FormBuilder/__stories__/Default.tsx +1 -1
  198. package/src/FormBuilder/__stories__/ErrorGrouping.tsx +1 -1
  199. package/src/FormBuilder/index.tsx +12 -6
  200. package/src/FormBuilder/scenarios.test.tsx +6 -6
  201. package/src/FormContext.tsx +5 -1
  202. package/src/MultiplicityField/MultiplicityField.stories.js +3 -0
  203. package/src/MultiplicityField/__stories__/Default.tsx +1 -1
  204. package/src/MultiplicityField/__stories__/PreviewDisplay.tsx +1 -1
  205. package/src/MultiplicityField/__stories__/WithExactLength.tsx +1 -1
  206. package/src/MultiplicityField/__stories__/WithMaxLength.tsx +1 -1
  207. package/src/MultiplicityField/__stories__/WithMinAndMaxLength.tsx +1 -1
  208. package/src/MultiplicityField/__stories__/WithMinLength.tsx +1 -1
  209. package/src/MultiplicityField/add-objects.tsx +2 -0
  210. package/src/MultiplicityField/index.tsx +3 -0
  211. package/src/MultiplicityField/types.ts +1 -0
  212. package/src/Questions/Questions.stories.js +3 -0
  213. package/src/Questions/__stories__/Default.tsx +1 -1
  214. package/src/inputs/AutoCompleteInput/AutoComplete.stories.js +3 -0
  215. package/src/inputs/AutoCompleteInput/__stories__/Default.tsx +1 -1
  216. package/src/inputs/AutoCompleteInput/__stories__/Multiple.tsx +1 -1
  217. package/src/inputs/Checkboxes/Checkboxes.stories.js +3 -0
  218. package/src/inputs/Checkboxes/__stories__/Conditional.tsx +1 -1
  219. package/src/inputs/Checkboxes/__stories__/Default.tsx +1 -1
  220. package/src/inputs/Checkboxes/__stories__/WithDivider.tsx +1 -1
  221. package/src/inputs/Checkboxes/index.tsx +1 -1
  222. package/src/inputs/DateInput/DateInput.stories.js +3 -0
  223. package/src/inputs/DateInput/__stories__/Default.tsx +1 -1
  224. package/src/inputs/DateInput/index.tsx +21 -7
  225. package/src/inputs/DateTimeInput/DateTimeInput.stories.js +3 -0
  226. package/src/inputs/DateTimeInput/__stories__/Default.tsx +1 -1
  227. package/src/inputs/DateTimeInput/index.tsx +24 -9
  228. package/src/inputs/FileInput/FileInput.stories.js +4 -0
  229. package/src/inputs/FileInput/__stories__/Default.tsx +1 -1
  230. package/src/inputs/FileInput/__stories__/WithBorderAndLink.tsx +34 -0
  231. package/src/inputs/FileInput/index.test.tsx +4 -0
  232. package/src/inputs/FileInput/index.tsx +41 -30
  233. package/src/inputs/ImageInput/ImageInput.stories.js +5 -1
  234. package/src/inputs/ImageInput/__stories__/Default.tsx +1 -1
  235. package/src/inputs/ImageInput/__stories__/MaxSize.tsx +3 -2
  236. package/src/inputs/ImageInput/__stories__/WithInitialValues.tsx +45 -0
  237. package/src/inputs/ImageInput/__stories__/WithInvalidImageDimension.tsx +1 -1
  238. package/src/inputs/ImageInput/__stories__/logo.d.ts +4 -0
  239. package/src/inputs/ImageInput/__stories__/logo.png +0 -0
  240. package/src/inputs/ImageInput/index.test.tsx +21 -17
  241. package/src/inputs/ImageInput/index.tsx +100 -48
  242. package/src/inputs/Input/Input.stories.js +5 -0
  243. package/src/inputs/Input/__stories__/AFM.tsx +1 -1
  244. package/src/inputs/Input/__stories__/AMKA.tsx +23 -0
  245. package/src/inputs/Input/__stories__/Boolean.tsx +1 -1
  246. package/src/inputs/Input/__stories__/Email.tsx +23 -0
  247. package/src/inputs/Input/__stories__/IBAN.tsx +1 -1
  248. package/src/inputs/Input/__stories__/Integer.tsx +1 -1
  249. package/src/inputs/Input/__stories__/LandlineNumber.tsx +1 -1
  250. package/src/inputs/Input/__stories__/MobilePhone.tsx +1 -1
  251. package/src/inputs/Input/__stories__/PhoneNumber.tsx +1 -1
  252. package/src/inputs/Input/__stories__/PostalCode.tsx +1 -1
  253. package/src/inputs/Input/__stories__/String.tsx +1 -1
  254. package/src/inputs/Input/__stories__/StringWithTrimValidation.tsx +1 -1
  255. package/src/inputs/Input/__stories__/TextWithLimit.tsx +1 -1
  256. package/src/inputs/Input/index.test.tsx +8 -0
  257. package/src/inputs/Input/index.tsx +5 -3
  258. package/src/inputs/Label/Label.stories.js +3 -0
  259. package/src/inputs/Label/__stories__/Default.tsx +1 -1
  260. package/src/inputs/OtpInput/OtpInput.stories.js +3 -0
  261. package/src/inputs/OtpInput/__stories__/Default.tsx +1 -1
  262. package/src/inputs/Radio/Radio.stories.js +3 -0
  263. package/src/inputs/Radio/__stories__/Conditional.tsx +1 -1
  264. package/src/inputs/Radio/__stories__/Default.tsx +1 -1
  265. package/src/inputs/Radio/__stories__/WithDivider.tsx +1 -1
  266. package/src/inputs/Select/Select.stories.js +3 -0
  267. package/src/inputs/Select/__stories__/Default.tsx +1 -1
  268. package/src/inputs/Select/index.tsx +7 -4
  269. package/src/inputs/inputsScenarios.ts +2 -2
  270. package/src/lazy.js +2 -1
  271. package/src/registry.js +6 -6
  272. package/src/types.tsx +2 -1
  273. package/src/utils.ts +27 -6
  274. package/src/validators/index.ts +16 -5
  275. package/src/validators/utils/amka.ts +39 -0
  276. package/src/validators/utils/file.ts +33 -19
  277. package/src/validators/utils/index.ts +4 -1
  278. package/types.d.ts +2 -1
  279. package/types.js.map +1 -1
  280. package/utils/index.js +20 -6
  281. package/utils.d.ts +2 -0
  282. package/utils.js.map +2 -2
  283. package/validators/index.d.ts +1 -1
  284. package/validators/index.js +11 -5
  285. package/validators/index.js.map +2 -2
  286. package/validators/utils/amka/index.js +36 -0
  287. package/{inputs/Input/inputsInputScenarios → validators/utils/amka}/package.json +1 -1
  288. package/validators/utils/amka.d.ts +6 -0
  289. package/validators/utils/amka.js.map +7 -0
  290. package/validators/utils/file/index.js +30 -17
  291. package/validators/utils/file.js.map +2 -2
  292. package/validators/utils/index.d.ts +1 -0
  293. package/validators/utils/index.js +4 -1
  294. package/validators/utils/index.js.map +2 -2
  295. package/cjs/inputs/Input/inputsInputScenarios/index.js +0 -439
  296. package/cjs/inputs/Input/inputsInputScenarios.js.map +0 -7
  297. package/inputs/Input/inputsInputScenarios/index.js +0 -406
  298. package/inputs/Input/inputsInputScenarios.d.ts +0 -57
  299. package/inputs/Input/inputsInputScenarios.js.map +0 -7
  300. package/src/inputs/Input/inputsInputScenarios.ts +0 -404
@@ -81,7 +81,7 @@ const fields = [
81
81
  },
82
82
  ] as FieldSpec[];
83
83
 
84
- export const Default = () => (
84
+ export const Default = (_: any) => (
85
85
  <FormBuilder
86
86
  onSubmit={(data) => {
87
87
  console.log(data);
@@ -81,7 +81,7 @@ const fields = [
81
81
  },
82
82
  ] as FieldSpec[];
83
83
 
84
- export const WithExactLength = () => (
84
+ export const WithExactLength = (_: any) => (
85
85
  <FormBuilder
86
86
  onSubmit={(data) => {
87
87
  console.log(data);
@@ -22,6 +22,8 @@ const fields = [
22
22
  secondary: 'Οι συνυπογράφοντες είναι άνθρωποι σαν και εμάς',
23
23
  },
24
24
  extra: {
25
+ noIndex: true,
26
+ border: false,
25
27
  variant: 'dialog',
26
28
  noHeader: false,
27
29
  label: {
@@ -145,15 +147,14 @@ const fields = [
145
147
  },
146
148
  ] as FieldSpec[];
147
149
 
148
- export const WithModal = () => (
150
+ export const WithModal = (_: any) => (
149
151
  <FormBuilder
150
152
  onSubmit={(data) => {
151
153
  console.log(data);
154
+ window.alert('Submit success');
152
155
  }}
153
156
  >
154
- <Field name="string" {...fields[0]} />
155
157
  <Field name="multiplicity" {...fields[1]} />
156
- <Field name="arrayofafm" {...fields[2]} />
157
158
  <Button>Συνέχεια</Button>
158
159
  </FormBuilder>
159
160
  );
@@ -7,7 +7,6 @@ import { FieldObject } from '@digigov/form/FieldObject';
7
7
  import { FieldsetLabel, Fieldset } from '@digigov/form/Fieldset';
8
8
  import { Card } from '@digigov/ui/content/Card';
9
9
  import { Button } from '@digigov/ui/form/Button';
10
- import { Hint } from '@digigov/ui/typography/Hint';
11
10
 
12
11
  export interface FieldArrayProps extends FieldProps {
13
12
  control: UseFormReturn['control'];
@@ -19,6 +18,7 @@ export interface FieldArrayProps extends FieldProps {
19
18
  getValues: UseFormReturn['getValues'];
20
19
  setValue: UseFormReturn['setValue'];
21
20
  reset: UseFormReturn['reset'];
21
+ resetField?: UseFormReturn['resetField'];
22
22
  Field: React.FC<FieldProps>;
23
23
  }
24
24
  export const FieldArray: React.FC<FieldArrayProps> = ({
@@ -33,36 +33,28 @@ export const FieldArray: React.FC<FieldArrayProps> = ({
33
33
  setValue,
34
34
  layout,
35
35
  reset,
36
+ resetField,
36
37
  label,
37
38
  Field,
38
39
  ...customField
39
40
  }) => {
40
- const { fields, append, remove } = useFieldArray({
41
+ const { append, remove } = useFieldArray({
41
42
  control,
42
43
  name,
43
44
  });
44
-
45
+ const fields = getValues(name) || [];
45
46
  return (
46
47
  <FieldBaseContainer
47
48
  label={label}
48
49
  layout={layout}
49
- error={
50
- formState.isSubmitted &&
51
- !formState.isSubmitting &&
52
- error?.message &&
53
- error
54
- ? error
55
- : undefined
56
- }
50
+ register={register}
51
+ error={error?.message && error ? error : undefined}
57
52
  hasError={formState.isSubmitted && !formState.isSubmitting && !!error}
58
53
  wrapper="fieldset"
59
54
  name={name}
55
+ labelSize={customField.extra?.labelSize}
56
+ controlled={true}
60
57
  >
61
- {fields.length === 0 && (
62
- <Hint {...customField.extra?.label.object?.nothing_added_props}>
63
- {customField.extra?.label.object?.nothing_added}
64
- </Hint>
65
- )}
66
58
  {customField.extra?.variant === 'dialog' ? (
67
59
  <FormDialog
68
60
  name={name}
@@ -78,6 +70,8 @@ export const FieldArray: React.FC<FieldArrayProps> = ({
78
70
  label={label}
79
71
  Field={Field}
80
72
  reset={reset}
73
+ resetField={resetField}
74
+ sortable={customField.extra.sortable}
81
75
  {...customField}
82
76
  />
83
77
  ) : (
@@ -85,7 +79,7 @@ export const FieldArray: React.FC<FieldArrayProps> = ({
85
79
  {fields.map((field, index) => (
86
80
  <Card
87
81
  variant={customField.extra?.border ? 'border' : 'divider'}
88
- key={field.id}
82
+ key={field.id || index}
89
83
  >
90
84
  <Fieldset>
91
85
  <FieldsetLabel>
@@ -114,19 +108,21 @@ export const FieldArray: React.FC<FieldArrayProps> = ({
114
108
  </Fieldset>
115
109
  </Card>
116
110
  ))}
117
- <Button
118
- type="button"
119
- name={`${name}-add-object`}
120
- color="secondary"
121
- variant={customField.extra?.label.object?.addButtonVariant}
122
- onClick={(ev) => {
123
- ev.preventDefault();
124
- append({});
125
- }}
126
- disabled={!customField?.editable}
127
- >
128
- {customField.extra?.label.object?.add}
129
- </Button>
111
+ {customField.editable && (
112
+ <Button
113
+ type="button"
114
+ name={`${name}-add-object`}
115
+ color="secondary"
116
+ variant={customField.extra?.label.object?.addButtonVariant}
117
+ onClick={(ev) => {
118
+ ev.preventDefault();
119
+ append({});
120
+ }}
121
+ disabled={!customField?.editable}
122
+ >
123
+ {customField.extra?.label.object?.add}
124
+ </Button>
125
+ )}
130
126
  </>
131
127
  )}
132
128
  </FieldBaseContainer>
@@ -1,7 +1,7 @@
1
1
  import React, { useMemo } from 'react';
2
2
  import { ErrorOption, UseFormReturn } from 'react-hook-form';
3
3
  import { FieldBase } from '@digigov/form/Field/FieldBase';
4
- import { CalculatedField, FieldProps } from '@digigov/form/Field/types';
4
+ import { FieldProps, CalculatedField } from '@digigov/form/Field/types';
5
5
  import {
6
6
  FIELD_COMPONENTS,
7
7
  ALTERNATIVE_COMPONENTS,
@@ -16,6 +16,7 @@ export interface FieldObjectProps extends Omit<FieldProps, 'key'> {
16
16
  control: UseFormReturn['control'];
17
17
  register: UseFormReturn['register'];
18
18
  reset: UseFormReturn['reset'];
19
+ resetField: UseFormReturn['resetField'];
19
20
  formState: UseFormReturn['formState'];
20
21
  error?: ErrorOption;
21
22
  defaultValue?: undefined;
@@ -29,6 +30,7 @@ export const FieldObject: React.FC<FieldObjectProps> = ({
29
30
  control,
30
31
  register,
31
32
  reset,
33
+ resetField,
32
34
  formState,
33
35
  error,
34
36
  defaultValue,
@@ -39,10 +41,12 @@ export const FieldObject: React.FC<FieldObjectProps> = ({
39
41
  return (
40
42
  <Fieldset>
41
43
  {label?.primary && (
42
- <FieldsetLegend size="sm">{t(label.primary)}</FieldsetLegend>
44
+ <FieldsetLegend size="sm" marginBottom={3}>
45
+ {t(label.primary)}
46
+ </FieldsetLegend>
43
47
  )}
44
48
  {label?.secondary && (
45
- <FieldsetCaption>{t(label.secondary)}</FieldsetCaption>
49
+ <FieldsetCaption marginBottom={3}>{t(label.secondary)}</FieldsetCaption>
46
50
  )}
47
51
  {extra?.fields.map((field) => (
48
52
  <FieldObjectItem
@@ -51,10 +55,11 @@ export const FieldObject: React.FC<FieldObjectProps> = ({
51
55
  control={control}
52
56
  register={register}
53
57
  reset={reset}
58
+ resetField={resetField}
54
59
  field={field}
55
60
  error={error && error[field.key]}
56
61
  formState={formState}
57
- defaultValue={defaultValue}
62
+ defaultValue={defaultValue?.[field.key] || undefined}
58
63
  Field={Field}
59
64
  />
60
65
  ))}
@@ -63,15 +68,16 @@ export const FieldObject: React.FC<FieldObjectProps> = ({
63
68
  };
64
69
 
65
70
  export interface FieldObjectItemProps {
71
+ key: string;
66
72
  name: string;
67
73
  field: FieldSpec;
68
74
  control: UseFormReturn['control'];
69
75
  register: UseFormReturn['register'];
70
76
  reset: UseFormReturn['reset'];
77
+ resetField: UseFormReturn['resetField'];
71
78
  formState: UseFormReturn['formState'];
72
79
  error?: ErrorOption;
73
80
  children?: React.ReactNode;
74
- // defaultValue?: FormData | undefined;
75
81
  defaultValue?: undefined;
76
82
  Field: React.FC<FieldProps>;
77
83
  }
@@ -84,6 +90,7 @@ const FieldObjectItem: React.FC<FieldObjectItemProps> = ({
84
90
  control,
85
91
  formState,
86
92
  reset,
93
+ resetField,
87
94
  register,
88
95
  defaultValue,
89
96
  Field,
@@ -93,19 +100,27 @@ const FieldObjectItem: React.FC<FieldObjectItemProps> = ({
93
100
  calculateField(children, field, FIELD_COMPONENTS, ALTERNATIVE_COMPONENTS),
94
101
  [field]
95
102
  );
96
- const customError = error ? error : formState?.errors[name];
97
- return (
98
- <FieldBase
99
- {...calculatedField}
100
- name={name}
101
- Field={Field}
102
- control={control}
103
- reset={reset}
104
- register={register}
105
- error={customError}
106
- defaultValue={defaultValue}
107
- />
108
- );
103
+ if (Field) {
104
+ if (!field.type) {
105
+ field.type = 'string';
106
+ }
107
+ return <Field {...field} name={name} />;
108
+ } else {
109
+ const customError = error ? error : formState?.errors[name];
110
+ return (
111
+ <FieldBase
112
+ {...calculatedField}
113
+ name={name}
114
+ Field={Field}
115
+ control={control}
116
+ reset={reset}
117
+ resetField={resetField}
118
+ register={register}
119
+ error={customError}
120
+ defaultValue={defaultValue}
121
+ />
122
+ );
123
+ }
109
124
  };
110
125
 
111
126
  export default FieldObject;
@@ -1,7 +1,10 @@
1
1
  import FormBuilder from '@digigov/form/FormBuilder';
2
+ import doc from './doc.mdx?raw';
2
3
  export default {
3
4
  title: 'Digigov Form/FormBuilder',
4
5
  component: FormBuilder,
6
+ tags: ['autodocs'],
7
+ markdown: doc,
5
8
  displayName: 'FormBuilder',
6
9
  };
7
10
  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 = () => (
52
+ export const AutoErrorGrouping = (_: any) => (
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 = () => (
9
+ export const Default = (_: any) => (
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 = () => (
6
+ export const ErrorGrouping = (_: any) => (
7
7
  <FormBuilder
8
8
  grid={true}
9
9
  onSubmit={(data) => {
@@ -1,10 +1,10 @@
1
- import React, { useCallback, useContext, useRef } from 'react';
1
+ import React, { useCallback, 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 } from '@digigov/form/FormContext';
7
+ import { FormContext, useFormContext } 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';
@@ -23,10 +23,11 @@ const FormBase = React.forwardRef(function FormBase(
23
23
  mode,
24
24
  initial,
25
25
  reValidateMode,
26
- shouldFocusError,
26
+ shouldFocusError = true,
27
27
  criteriaMode,
28
28
  componentRegistry,
29
29
  grid,
30
+ errors,
30
31
  ...props
31
32
  }: FormBaseProps,
32
33
  ref: React.Ref<HTMLFormElement>
@@ -49,6 +50,13 @@ const FormBase = React.forwardRef(function FormBase(
49
50
  },
50
51
  [onSubmit]
51
52
  );
53
+ useEffect(() => {
54
+ if (errors) {
55
+ for (const fieldName in errors) {
56
+ form.setError(fieldName, errors[fieldName]);
57
+ }
58
+ }
59
+ }, [errors]);
52
60
  const submit = form.handleSubmit(handleSubmit);
53
61
  const ctx = {
54
62
  fieldsMap,
@@ -72,6 +80,7 @@ const FormBase = React.forwardRef(function FormBase(
72
80
  formRef: ref,
73
81
  submit,
74
82
  };
83
+
75
84
  return (
76
85
  <FormContext.Provider value={ctx}>
77
86
  <Form grid={grid} onSubmit={submit} ref={ref} {...props}>
@@ -118,9 +127,6 @@ const groupFieldsByLayout = (fields) => {
118
127
  return sizes;
119
128
  }, {});
120
129
  };
121
- const useFormContext = () => {
122
- return useContext(FormContext);
123
- };
124
130
  const useFormValues = () => {
125
131
  const ctx = useFormContext();
126
132
  return ctx.getValues();
@@ -652,9 +652,9 @@ const el = {
652
652
  email: 'Συμπληρώστε μια έγκυρη ηλεκτρονική διεύθυνση (e-mail).',
653
653
  afm: 'Ο Α.Φ.Μ που πληκτρολογήσατε είναι λανθασμένος.',
654
654
  file_size:
655
- 'Το μέγεθος του αρχείου είναι μεγαλύτερο απο το επιτρεπόμενο ({{maxSizeToMb}}Mb).',
655
+ 'Το μέγεθος του αρχείου είναι μεγαλύτερο από το επιτρεπόμενο ({{maxSize}} Bytes).',
656
656
  image_size:
657
- 'Το μέγεθος της φωτογραφίας είναι μεγαλύτερο απο το επιτρεπόμενο ({{maxSizeToMb}}Mb).',
657
+ 'Το μέγεθος της φωτογραφίας είναι μεγαλύτερο από το επιτρεπόμενο ({{maxSize}} Bytes).',
658
658
  mobile_phone: 'Συμπληρώστε έναν έγκυρο αριθμό κινητού τηλεφώνου.',
659
659
  phone_number: 'Συμπληρώστε έναν έγκυρο αριθμό τηλεφώνου.',
660
660
  landline: 'Συμπληρώστε έναν έγκυρο αριθμό σταθερού τηλεφώνου.',
@@ -1122,7 +1122,7 @@ const inputsScenarios = [
1122
1122
  type: 'error',
1123
1123
  fieldKey: 'image',
1124
1124
  args: {
1125
- maxSizeToMb: 0.0003,
1125
+ maxSize: 300,
1126
1126
  },
1127
1127
  text: el.form.error.image_size,
1128
1128
  },
@@ -1130,7 +1130,7 @@ const inputsScenarios = [
1130
1130
  type: 'error',
1131
1131
  fieldKey: 'file',
1132
1132
  args: {
1133
- maxSizeToMb: 0.0003,
1133
+ maxSize: 300,
1134
1134
  },
1135
1135
  text: el.form.error.file_size,
1136
1136
  },
@@ -1564,7 +1564,7 @@ const inputsInputScenarios = [
1564
1564
  },
1565
1565
  {
1566
1566
  fieldKey: 'email',
1567
- value: '23232',
1567
+ value: 'example@mail.',
1568
1568
  },
1569
1569
  {
1570
1570
  fieldKey: 'location',
@@ -1958,7 +1958,7 @@ for (const scenario of scenarios) {
1958
1958
  auto={true}
1959
1959
  grid={true}
1960
1960
  fields={scenario.fields}
1961
- onSubmit={() => {}}
1961
+ onSubmit={() => { }}
1962
1962
  />
1963
1963
  );
1964
1964
  await fillFields(page, formBuilder, scenario);
@@ -1,7 +1,11 @@
1
- import React, { createContext } from 'react';
1
+ import React, { createContext, useContext } 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,7 +1,10 @@
1
1
  import MultiplicityField from '@digigov/form/MultiplicityField';
2
+ import doc from './doc.mdx?raw';
2
3
  export default {
3
4
  title: 'Digigov Form/MultiplicityField',
4
5
  component: MultiplicityField,
6
+ tags: ['autodocs'],
7
+ markdown: doc,
5
8
  displayName: 'MultiplicityField',
6
9
  };
7
10
  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 = () => (
88
+ export const Default = (_: any) => (
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 = () => (
64
+ export const PreviewDisplay = (_: any) => (
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 = () => (
87
+ export const WithExactLength = (_: any) => (
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 = () => (
90
+ export const WithMaxLength = (_: any) => (
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 = () => (
91
+ export const WithMinAndMaxLength = (_: any) => (
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 = () => (
90
+ export const WithMinLength = (_: any) => (
91
91
  <FormBuilder
92
92
  onSubmit={(data) => {
93
93
  console.log(data);
@@ -47,6 +47,7 @@ export const AddObjects: React.FC<AddObjectsProps> = ({
47
47
  setValue,
48
48
  stashedObjects,
49
49
  getValues,
50
+ resetField,
50
51
  onStash,
51
52
  error,
52
53
  Field,
@@ -187,6 +188,7 @@ export const AddObjects: React.FC<AddObjectsProps> = ({
187
188
  control={control}
188
189
  register={register}
189
190
  reset={reset}
191
+ resetField={resetField}
190
192
  Field={Field}
191
193
  error={
192
194
  extra?.max - stashedObjects.length === 0 ||
@@ -31,6 +31,7 @@ export const Multiplicity: React.FC<MultiplicityProps> = ({
31
31
  setValue,
32
32
  getValues,
33
33
  unregister,
34
+ resetField,
34
35
  Field,
35
36
  }) => {
36
37
  const { fields, append, remove } = useFieldArray({
@@ -60,6 +61,7 @@ export const Multiplicity: React.FC<MultiplicityProps> = ({
60
61
  hasError={formState.isSubmitted && !formState.isSubmitting && !!error}
61
62
  wrapper="fieldset"
62
63
  name={name}
64
+ register={register}
63
65
  >
64
66
  {stashedObjects.length > 0 ? (
65
67
  <div>
@@ -98,6 +100,7 @@ export const Multiplicity: React.FC<MultiplicityProps> = ({
98
100
  getValues={getValues}
99
101
  unregister={unregister}
100
102
  trigger={trigger}
103
+ resetField={resetField}
101
104
  clearErrors={clearErrors}
102
105
  Field={Field}
103
106
  />
@@ -12,6 +12,7 @@ export interface MultiplicityProps
12
12
  setValue: UseFormReturn['setValue'];
13
13
  getValues: UseFormReturn['getValues'];
14
14
  unregister: UseFormReturn['unregister'];
15
+ resetField?: UseFormReturn['resetField'];
15
16
  error?: ErrorOption;
16
17
  extra?: Record<string, any>;
17
18
  label?: FieldSpec['label'];
@@ -1,7 +1,10 @@
1
1
  import Questions from '@digigov/form/Questions';
2
+ import doc from './doc.mdx?raw';
2
3
  export default {
3
4
  title: 'Digigov Form/Questions',
4
5
  component: Questions,
6
+ tags: ['autodocs'],
7
+ markdown: doc,
5
8
  displayName: 'Questions',
6
9
  };
7
10
  export { Default } from '@digigov/form/Questions/__stories__/Default';
@@ -75,7 +75,7 @@ const steps = [
75
75
  },
76
76
  ];
77
77
 
78
- export function Default() {
78
+ export function Default(_: any) {
79
79
  return (
80
80
  <BasicLayout>
81
81
  <Top>
@@ -1,7 +1,10 @@
1
1
  import AutoComplete from '@digigov/form/inputs/AutoCompleteInput';
2
+ import doc from './doc.mdx?raw';
2
3
  export default {
3
4
  title: 'Digigov Form/inputs/AutoCompleteInput',
4
5
  component: AutoComplete,
6
+ tags: ['autodocs'],
7
+ markdown: doc,
5
8
  displayName: 'AutoCompleteInput',
6
9
  };
7
10
  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 = () => (
32
+ export const Default = (_: any) => (
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 = () => (
32
+ export const Multiple = (_: any) => (
33
33
  <FormBuilder
34
34
  fields={fields}
35
35
  onSubmit={(data) => {
@@ -1,7 +1,10 @@
1
1
  import Checkboxes from '@digigov/form/inputs/Checkboxes';
2
+ import doc from './doc.mdx?raw';
2
3
  export default {
3
4
  title: 'Digigov Form/inputs/Checkboxes',
4
5
  component: Checkboxes,
6
+ tags: ['autodocs'],
7
+ markdown: doc,
5
8
  displayName: 'Checkboxes',
6
9
  };
7
10
  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 = () => (
87
+ export const Conditional = (_: any) => (
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 = () => (
5
+ export const Default = (_: any) => (
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 = () => (
5
+ export const WithDivider = (_: any) => (
6
6
  <FormBuilder
7
7
  onSubmit={(data) => {
8
8
  console.log(data);