@digigov/form 2.0.0-76ec20a0 → 2.0.0-7d765d3c

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 (459) hide show
  1. package/Field/ErrorGroup.d.ts +3 -3
  2. package/Field/ErrorGroup.js.map +1 -1
  3. package/Field/FieldBase/index.js +7 -4
  4. package/Field/FieldBase.d.ts +1 -1
  5. package/Field/FieldBase.js.map +2 -2
  6. package/Field/FieldBaseContainer/index.js +37 -18
  7. package/Field/FieldBaseContainer.d.ts +2 -2
  8. package/Field/FieldBaseContainer.js.map +2 -2
  9. package/Field/FieldConditional/index.js +4 -0
  10. package/Field/FieldConditional.d.ts +1 -1
  11. package/Field/FieldConditional.js.map +2 -2
  12. package/Field/index.d.ts +1 -1
  13. package/Field/index.js +25 -29
  14. package/Field/index.js.map +2 -2
  15. package/Field/types.d.ts +20 -12
  16. package/Field/utils/evaluateFieldWithConditions.d.ts +2 -2
  17. package/Field/utils/evaluateFieldWithConditions.js.map +2 -2
  18. package/Field/utils/resolveField/index.js +35 -0
  19. package/Field/utils/{calculateField → resolveField}/package.json +1 -1
  20. package/Field/utils/resolveField.d.ts +3 -0
  21. package/Field/utils/resolveField.js.map +7 -0
  22. package/Field/utils/useField/index.js +12 -3
  23. package/Field/utils/useField.d.ts +1 -1
  24. package/Field/utils/useField.js.map +2 -2
  25. package/FieldArray/BaseFieldArray/index.js +76 -0
  26. package/FieldArray/BaseFieldArray/package.json +6 -0
  27. package/FieldArray/BaseFieldArray.d.ts +5 -0
  28. package/FieldArray/BaseFieldArray.js.map +7 -0
  29. package/FieldArray/FormDialog/ArrayItemDisplay/index.js +97 -0
  30. package/FieldArray/FormDialog/ArrayItemDisplay/package.json +6 -0
  31. package/FieldArray/FormDialog/ArrayItemDisplay.d.ts +22 -0
  32. package/FieldArray/FormDialog/ArrayItemDisplay.js.map +7 -0
  33. package/FieldArray/FormDialog/ArrayItemHeader/index.js +11 -0
  34. package/FieldArray/FormDialog/ArrayItemHeader/package.json +6 -0
  35. package/FieldArray/FormDialog/ArrayItemHeader.d.ts +5 -0
  36. package/FieldArray/FormDialog/ArrayItemHeader.js.map +7 -0
  37. package/FieldArray/FormDialog/ArrayItemModal/index.js +158 -0
  38. package/{inputs/Input/inputsInputScenarios → FieldArray/FormDialog/ArrayItemModal}/package.json +1 -1
  39. package/FieldArray/FormDialog/ArrayItemModal.d.ts +26 -0
  40. package/FieldArray/FormDialog/ArrayItemModal.js.map +7 -0
  41. package/FieldArray/FormDialog/index.d.ts +19 -0
  42. package/FieldArray/FormDialog/index.js +152 -258
  43. package/FieldArray/FormDialog/index.js.map +7 -0
  44. package/FieldArray/index.d.ts +5 -2
  45. package/FieldArray/index.js +36 -57
  46. package/FieldArray/index.js.map +2 -2
  47. package/FieldObject/index.d.ts +7 -4
  48. package/FieldObject/index.js +29 -25
  49. package/FieldObject/index.js.map +2 -2
  50. package/Fieldset/FieldsetWithContext.js.map +1 -1
  51. package/Fieldset/index.d.ts +1 -1
  52. package/Fieldset/index.js.map +1 -1
  53. package/Fieldset/types.d.ts +2 -2
  54. package/FormBuilder/index.d.ts +2 -2
  55. package/FormBuilder/index.js +163 -134
  56. package/FormBuilder/index.js.map +2 -2
  57. package/FormContext/index.js +6 -2
  58. package/FormContext.d.ts +3 -2
  59. package/FormContext.js.map +2 -2
  60. package/MultiplicityField/add-objects/index.js +12 -19
  61. package/MultiplicityField/add-objects.d.ts +1 -1
  62. package/MultiplicityField/add-objects.js.map +2 -2
  63. package/MultiplicityField/index.d.ts +2 -2
  64. package/MultiplicityField/index.js +4 -1
  65. package/MultiplicityField/index.js.map +2 -2
  66. package/MultiplicityField/types.d.ts +3 -2
  67. package/Questions/Questions.d.ts +1 -1
  68. package/Questions/Questions.js.map +1 -1
  69. package/Questions/QuestionsContext.d.ts +1 -1
  70. package/Questions/QuestionsContext.js.map +1 -1
  71. package/Questions/Step/Step.d.ts +1 -1
  72. package/Questions/Step/Step.js.map +1 -1
  73. package/Questions/Step/StepArrayReview.d.ts +1 -1
  74. package/Questions/Step/StepArrayReview.js.map +1 -1
  75. package/Questions/Step/StepContext.d.ts +1 -1
  76. package/Questions/Step/StepContext.js.map +1 -1
  77. package/Questions/Step/StepDescription.d.ts +1 -1
  78. package/Questions/Step/StepDescription.js.map +2 -2
  79. package/Questions/Step/StepForm.d.ts +2 -2
  80. package/Questions/Step/StepForm.js.map +1 -1
  81. package/Questions/Step/StepQuote.d.ts +1 -1
  82. package/Questions/Step/StepQuote.js.map +2 -2
  83. package/Questions/Step/StepTitle.d.ts +1 -1
  84. package/Questions/Step/StepTitle.js.map +2 -2
  85. package/Questions/Step/getAddMoreFields.d.ts +2 -2
  86. package/Questions/Step/getAddMoreFields.js.map +1 -1
  87. package/Questions/Step/types.d.ts +1 -1
  88. package/Questions/getNextStep.d.ts +1 -1
  89. package/Questions/getNextStep.js.map +1 -1
  90. package/Questions/types.d.ts +1 -1
  91. package/cjs/Field/ErrorGroup.js.map +1 -1
  92. package/cjs/Field/FieldBase/index.js +7 -4
  93. package/cjs/Field/FieldBase.js.map +2 -2
  94. package/cjs/Field/FieldBaseContainer/index.js +36 -17
  95. package/cjs/Field/FieldBaseContainer.js.map +3 -3
  96. package/cjs/Field/FieldConditional/index.js +4 -0
  97. package/cjs/Field/FieldConditional.js.map +2 -2
  98. package/cjs/Field/index.js +25 -26
  99. package/cjs/Field/index.js.map +2 -2
  100. package/cjs/Field/types.js.map +1 -1
  101. package/cjs/Field/utils/evaluateFieldWithConditions.js.map +2 -2
  102. package/cjs/Field/utils/resolveField/index.js +55 -0
  103. package/cjs/Field/utils/resolveField.js.map +7 -0
  104. package/cjs/Field/utils/useField/index.js +12 -3
  105. package/cjs/Field/utils/useField.js.map +2 -2
  106. package/cjs/FieldArray/BaseFieldArray/index.js +109 -0
  107. package/cjs/FieldArray/BaseFieldArray.js.map +7 -0
  108. package/cjs/FieldArray/FormDialog/ArrayItemDisplay/index.js +130 -0
  109. package/cjs/FieldArray/FormDialog/ArrayItemDisplay.js.map +7 -0
  110. package/cjs/{locales/el → FieldArray/FormDialog/ArrayItemHeader}/index.js +16 -7
  111. package/cjs/FieldArray/FormDialog/ArrayItemHeader.js.map +7 -0
  112. package/cjs/FieldArray/FormDialog/ArrayItemModal/index.js +186 -0
  113. package/cjs/FieldArray/FormDialog/ArrayItemModal.js.map +7 -0
  114. package/cjs/FieldArray/FormDialog/index.js +148 -243
  115. package/cjs/FieldArray/FormDialog/index.js.map +7 -0
  116. package/cjs/FieldArray/index.js +35 -56
  117. package/cjs/FieldArray/index.js.map +3 -3
  118. package/cjs/FieldObject/index.js +29 -22
  119. package/cjs/FieldObject/index.js.map +2 -2
  120. package/cjs/Fieldset/FieldsetWithContext.js.map +1 -1
  121. package/cjs/Fieldset/index.js.map +1 -1
  122. package/cjs/Fieldset/types.js.map +1 -1
  123. package/cjs/FormBuilder/index.js +164 -135
  124. package/cjs/FormBuilder/index.js.map +3 -3
  125. package/cjs/FormContext/index.js +7 -2
  126. package/cjs/FormContext.js.map +2 -2
  127. package/cjs/MultiplicityField/add-objects/index.js +11 -13
  128. package/cjs/MultiplicityField/add-objects.js.map +2 -2
  129. package/cjs/MultiplicityField/index.js +4 -1
  130. package/cjs/MultiplicityField/index.js.map +2 -2
  131. package/cjs/MultiplicityField/types.js.map +1 -1
  132. package/cjs/Questions/Questions.js.map +1 -1
  133. package/cjs/Questions/QuestionsContext.js.map +1 -1
  134. package/cjs/Questions/Step/Step.js.map +1 -1
  135. package/cjs/Questions/Step/StepArrayReview.js.map +1 -1
  136. package/cjs/Questions/Step/StepContext.js.map +1 -1
  137. package/cjs/Questions/Step/StepDescription.js.map +2 -2
  138. package/cjs/Questions/Step/StepForm.js.map +1 -1
  139. package/cjs/Questions/Step/StepQuote.js.map +2 -2
  140. package/cjs/Questions/Step/StepTitle.js.map +2 -2
  141. package/cjs/Questions/Step/getAddMoreFields.js.map +1 -1
  142. package/cjs/Questions/Step/types.js.map +1 -1
  143. package/cjs/Questions/getNextStep.js.map +1 -1
  144. package/cjs/Questions/types.js.map +1 -1
  145. package/cjs/hooks/useFieldFocusManager/index.js +135 -0
  146. package/cjs/hooks/useFieldFocusManager.js.map +7 -0
  147. package/cjs/hooks/utils/index.js +98 -0
  148. package/cjs/hooks/utils.js.map +7 -0
  149. package/cjs/inputs/AutoCompleteInput/index.js.map +2 -2
  150. package/cjs/inputs/Checkboxes/index.js +67 -63
  151. package/cjs/inputs/Checkboxes/index.js.map +2 -2
  152. package/cjs/inputs/DateInput/index.js +51 -19
  153. package/cjs/inputs/DateInput/index.js.map +2 -2
  154. package/cjs/inputs/DateTimeInput/index.js +78 -39
  155. package/cjs/inputs/DateTimeInput/index.js.map +2 -2
  156. package/cjs/inputs/FileInput/index.js +52 -29
  157. package/cjs/inputs/FileInput/index.js.map +2 -2
  158. package/cjs/inputs/ImageInput/__stories__/logo.d/index.js +1 -0
  159. package/cjs/inputs/ImageInput/__stories__/logo.d.js.map +7 -0
  160. package/cjs/inputs/ImageInput/index.js +41 -10
  161. package/cjs/inputs/ImageInput/index.js.map +2 -2
  162. package/cjs/inputs/Input/index.js +55 -57
  163. package/cjs/inputs/Input/index.js.map +2 -2
  164. package/cjs/inputs/Label/index.js.map +1 -1
  165. package/cjs/inputs/OtpInput/index.js +36 -31
  166. package/cjs/inputs/OtpInput/index.js.map +2 -2
  167. package/cjs/inputs/Radio/index.js +5 -4
  168. package/cjs/inputs/Radio/index.js.map +3 -3
  169. package/cjs/inputs/Select/index.js +4 -3
  170. package/cjs/inputs/Select/index.js.map +2 -2
  171. package/cjs/{Field/utils → inputs/registry}/index.js +7 -5
  172. package/cjs/inputs/registry.js.map +7 -0
  173. package/cjs/lazy/index.js +10 -9
  174. package/cjs/lazy.js.map +2 -2
  175. package/cjs/registry/index.js +26 -18
  176. package/cjs/registry.js.map +2 -2
  177. package/cjs/types.js.map +1 -1
  178. package/cjs/utils/index.js +20 -6
  179. package/cjs/utils.js.map +2 -2
  180. package/cjs/validators/index.js +11 -6
  181. package/cjs/validators/index.js.map +2 -2
  182. package/cjs/validators/types.js.map +1 -1
  183. package/cjs/validators/utils/amka/index.js +60 -0
  184. package/cjs/validators/utils/amka.js.map +7 -0
  185. package/cjs/validators/utils/date/index.js +26 -3
  186. package/cjs/validators/utils/date.js.map +2 -2
  187. package/cjs/validators/utils/datetime/index.js +118 -24
  188. package/cjs/validators/utils/datetime.js.map +2 -2
  189. package/cjs/validators/utils/file/index.js +30 -17
  190. package/cjs/validators/utils/file.js.map +2 -2
  191. package/cjs/validators/utils/iban.js.map +1 -1
  192. package/cjs/validators/utils/image.js.map +1 -1
  193. package/cjs/validators/utils/index.js +5 -1
  194. package/cjs/validators/utils/index.js.map +2 -2
  195. package/cjs/validators/utils/int.js.map +1 -1
  196. package/cjs/validators/utils/number.js.map +1 -1
  197. package/cjs/validators/utils/otp.js.map +1 -1
  198. package/cjs/validators/utils/phone.js.map +1 -1
  199. package/cjs/validators/utils/postal_code.js.map +1 -1
  200. package/cjs/validators/utils/text_limit.js.map +1 -1
  201. package/hooks/useFieldFocusManager/index.js +116 -0
  202. package/hooks/useFieldFocusManager/package.json +6 -0
  203. package/hooks/useFieldFocusManager.d.ts +25 -0
  204. package/hooks/useFieldFocusManager.js.map +7 -0
  205. package/hooks/utils/index.js +73 -0
  206. package/{Field → hooks}/utils/package.json +1 -1
  207. package/hooks/utils.d.ts +18 -0
  208. package/hooks/utils.js.map +7 -0
  209. package/index.js +1 -1
  210. package/inputs/AutoCompleteInput/index.d.ts +3 -3
  211. package/inputs/AutoCompleteInput/index.js +1 -3
  212. package/inputs/AutoCompleteInput/index.js.map +2 -2
  213. package/inputs/Checkboxes/index.d.ts +3 -3
  214. package/inputs/Checkboxes/index.js +67 -63
  215. package/inputs/Checkboxes/index.js.map +2 -2
  216. package/inputs/DateInput/DateInput.stories.d.ts +4 -0
  217. package/inputs/DateInput/__stories__/WithDefaultValue.d.ts +3 -0
  218. package/inputs/DateInput/__stories__/WithInitialValue.d.ts +3 -0
  219. package/inputs/DateInput/__stories__/WithWrongDefaultValue.d.ts +3 -0
  220. package/inputs/DateInput/__stories__/WithWrongInitialValue.d.ts +3 -0
  221. package/inputs/DateInput/index.d.ts +2 -5
  222. package/inputs/DateInput/index.js +52 -20
  223. package/inputs/DateInput/index.js.map +2 -2
  224. package/inputs/DateTimeInput/DateTimeInput.stories.d.ts +8 -3
  225. package/inputs/DateTimeInput/__stories__/WithDefaultValue.d.ts +3 -0
  226. package/inputs/DateTimeInput/__stories__/WithInitialValue.d.ts +3 -0
  227. package/inputs/DateTimeInput/__stories__/WithWrongDefaultValue.d.ts +3 -0
  228. package/inputs/DateTimeInput/__stories__/WithWrongInitialValue.d.ts +3 -0
  229. package/inputs/DateTimeInput/index.d.ts +2 -5
  230. package/inputs/DateTimeInput/index.js +79 -40
  231. package/inputs/DateTimeInput/index.js.map +2 -2
  232. package/inputs/FileInput/FileInput.stories.d.ts +1 -0
  233. package/inputs/FileInput/__stories__/WithBorderAndLink.d.ts +3 -0
  234. package/inputs/FileInput/index.d.ts +12 -5
  235. package/inputs/FileInput/index.js +53 -30
  236. package/inputs/FileInput/index.js.map +2 -2
  237. package/inputs/ImageInput/ImageInput.stories.d.ts +2 -1
  238. package/inputs/ImageInput/__stories__/WithInitialValues.d.ts +3 -0
  239. package/inputs/ImageInput/__stories__/logo.d/index.js +1 -0
  240. package/inputs/ImageInput/__stories__/logo.d/package.json +6 -0
  241. package/inputs/ImageInput/__stories__/logo.d.js.map +7 -0
  242. package/inputs/ImageInput/index.d.ts +10 -2
  243. package/inputs/ImageInput/index.js +42 -11
  244. package/inputs/ImageInput/index.js.map +2 -2
  245. package/inputs/Input/Input.stories.d.ts +2 -0
  246. package/inputs/Input/__stories__/AMKA.d.ts +3 -0
  247. package/inputs/Input/__stories__/Email.d.ts +3 -0
  248. package/inputs/Input/index.d.ts +4 -3
  249. package/inputs/Input/index.js +55 -57
  250. package/inputs/Input/index.js.map +2 -2
  251. package/inputs/Label/index.d.ts +1 -1
  252. package/inputs/Label/index.js.map +1 -1
  253. package/inputs/OtpInput/index.d.ts +1 -5
  254. package/inputs/OtpInput/index.js +36 -31
  255. package/inputs/OtpInput/index.js.map +2 -2
  256. package/inputs/Radio/index.d.ts +4 -4
  257. package/inputs/Radio/index.js +5 -4
  258. package/inputs/Radio/index.js.map +3 -3
  259. package/inputs/Select/index.d.ts +4 -3
  260. package/inputs/Select/index.js +4 -3
  261. package/inputs/Select/index.js.map +2 -2
  262. package/{Field/utils → inputs/registry}/index.js +4 -2
  263. package/{locales/el → inputs/registry}/package.json +1 -1
  264. package/{Field/utils/index.d.ts → inputs/registry.d.ts} +2 -1
  265. package/inputs/registry.js.map +7 -0
  266. package/lazy/index.js +10 -9
  267. package/package.json +8 -8
  268. package/registry/index.js +26 -18
  269. package/src/Field/ErrorGroup.tsx +3 -3
  270. package/src/Field/FieldBase.tsx +7 -4
  271. package/src/Field/FieldBaseContainer.tsx +69 -48
  272. package/src/Field/FieldConditional.tsx +5 -1
  273. package/src/Field/index.tsx +30 -38
  274. package/src/Field/types.tsx +21 -14
  275. package/src/Field/utils/evaluateFieldWithConditions.ts +5 -2
  276. package/src/Field/utils/resolveField.ts +58 -0
  277. package/src/Field/utils/useField.ts +12 -2
  278. package/src/FieldArray/BaseFieldArray.tsx +97 -0
  279. package/src/FieldArray/FormDialog/ArrayItemDisplay.tsx +165 -0
  280. package/src/FieldArray/FormDialog/ArrayItemHeader.tsx +15 -0
  281. package/src/FieldArray/FormDialog/ArrayItemModal.tsx +223 -0
  282. package/src/FieldArray/FormDialog/index.tsx +233 -0
  283. package/src/FieldArray/__stories__/WithModal.tsx +3 -2
  284. package/src/FieldArray/__tests__/multiplicity-attachment.spec.tsx +219 -0
  285. package/src/FieldArray/__tests__/multiplicity-required.spec.tsx +131 -0
  286. package/src/FieldArray/__tests__/preference-multiple-choice.spec.tsx +222 -0
  287. package/src/FieldArray/index.spec.tsx +355 -0
  288. package/src/FieldArray/index.tsx +41 -72
  289. package/src/FieldObject/index.tsx +36 -31
  290. package/src/Fieldset/FieldsetWithContext.tsx +1 -1
  291. package/src/Fieldset/index.tsx +1 -1
  292. package/src/Fieldset/types.tsx +2 -2
  293. package/src/FormBuilder/index.tsx +197 -146
  294. package/src/FormBuilder/scenarios.test.tsx +763 -5
  295. package/src/FormContext.tsx +7 -2
  296. package/src/MultiplicityField/add-objects.tsx +14 -21
  297. package/src/MultiplicityField/index.tsx +6 -2
  298. package/src/MultiplicityField/types.ts +6 -2
  299. package/src/Questions/Questions.tsx +2 -2
  300. package/src/Questions/QuestionsContext.tsx +1 -1
  301. package/src/Questions/Step/Step.tsx +1 -1
  302. package/src/Questions/Step/StepArrayReview.tsx +2 -2
  303. package/src/Questions/Step/StepContext.tsx +1 -1
  304. package/src/Questions/Step/StepDescription.tsx +2 -1
  305. package/src/Questions/Step/StepForm.tsx +2 -2
  306. package/src/Questions/Step/StepQuote.tsx +2 -1
  307. package/src/Questions/Step/StepTitle.tsx +2 -1
  308. package/src/Questions/Step/getAddMoreFields.tsx +2 -2
  309. package/src/Questions/Step/types.tsx +1 -1
  310. package/src/Questions/getNextStep.tsx +1 -1
  311. package/src/Questions/types.tsx +1 -1
  312. package/src/hooks/__tests__/useFieldFocusManager.spec.tsx +1079 -0
  313. package/src/hooks/__tests__/utils.spec.ts +568 -0
  314. package/src/hooks/useFieldFocusManager.ts +162 -0
  315. package/src/hooks/utils.ts +122 -0
  316. package/src/inputs/AutoCompleteInput/index.tsx +4 -6
  317. package/src/inputs/Checkboxes/index.tsx +95 -91
  318. package/src/inputs/DateInput/DateInput.stories.js +4 -0
  319. package/src/inputs/DateInput/__stories__/WithDefaultValue.tsx +26 -0
  320. package/src/inputs/DateInput/__stories__/WithInitialValue.tsx +28 -0
  321. package/src/inputs/DateInput/__stories__/WithWrongDefaultValue.tsx +26 -0
  322. package/src/inputs/DateInput/__stories__/WithWrongInitialValue.tsx +28 -0
  323. package/src/inputs/DateInput/index.test.tsx +16 -0
  324. package/src/inputs/DateInput/index.tsx +65 -20
  325. package/src/inputs/DateTimeInput/DateTimeInput.stories.js +9 -6
  326. package/src/inputs/DateTimeInput/__stories__/WithDefaultValue.tsx +26 -0
  327. package/src/inputs/DateTimeInput/__stories__/WithInitialValue.tsx +28 -0
  328. package/src/inputs/DateTimeInput/__stories__/WithWrongDefaultValue.tsx +26 -0
  329. package/src/inputs/DateTimeInput/__stories__/WithWrongInitialValue.tsx +28 -0
  330. package/src/inputs/DateTimeInput/index.test.tsx +16 -0
  331. package/src/inputs/DateTimeInput/index.tsx +92 -40
  332. package/src/inputs/FileInput/FileInput.stories.js +1 -0
  333. package/src/inputs/FileInput/__stories__/WithBorderAndLink.tsx +34 -0
  334. package/src/inputs/FileInput/index.test.tsx +4 -0
  335. package/src/inputs/FileInput/index.tsx +91 -47
  336. package/src/inputs/ImageInput/ImageInput.stories.js +2 -1
  337. package/src/inputs/ImageInput/__stories__/MaxSize.tsx +2 -1
  338. package/src/inputs/ImageInput/__stories__/WithInitialValues.tsx +45 -0
  339. package/src/inputs/ImageInput/__stories__/logo.d.ts +4 -0
  340. package/src/inputs/ImageInput/__stories__/logo.png +0 -0
  341. package/src/inputs/ImageInput/index.test.tsx +21 -17
  342. package/src/inputs/ImageInput/index.tsx +101 -49
  343. package/src/inputs/Input/Input.stories.js +2 -0
  344. package/src/inputs/Input/__stories__/AMKA.tsx +23 -0
  345. package/src/inputs/Input/__stories__/Email.tsx +23 -0
  346. package/src/inputs/Input/index.test.tsx +8 -0
  347. package/src/inputs/Input/index.tsx +76 -73
  348. package/src/inputs/Label/index.tsx +1 -1
  349. package/src/inputs/OtpInput/index.tsx +43 -34
  350. package/src/inputs/Radio/index.tsx +29 -21
  351. package/src/inputs/Select/index.tsx +9 -6
  352. package/src/{Field/utils/index.ts → inputs/registry.ts} +5 -1
  353. package/src/lazy.js +10 -9
  354. package/src/registry.js +26 -18
  355. package/src/types.tsx +13 -5
  356. package/src/utils.ts +30 -8
  357. package/src/validators/index.ts +27 -15
  358. package/src/validators/types.ts +1 -1
  359. package/src/validators/utils/amka.ts +39 -0
  360. package/src/validators/utils/date.ts +30 -6
  361. package/src/validators/utils/datetime.ts +123 -31
  362. package/src/validators/utils/file.ts +35 -21
  363. package/src/validators/utils/iban.ts +2 -2
  364. package/src/validators/utils/image.ts +2 -2
  365. package/src/validators/utils/index.ts +6 -3
  366. package/src/validators/utils/int.ts +1 -1
  367. package/src/validators/utils/number.ts +1 -1
  368. package/src/validators/utils/otp.ts +2 -2
  369. package/src/validators/utils/phone.ts +2 -2
  370. package/src/validators/utils/postal_code.ts +2 -2
  371. package/src/validators/utils/text_limit.ts +2 -2
  372. package/types.d.ts +9 -4
  373. package/types.js.map +1 -1
  374. package/utils/index.js +20 -6
  375. package/utils.d.ts +3 -1
  376. package/utils.js.map +2 -2
  377. package/validators/index.d.ts +6 -6
  378. package/validators/index.js +12 -6
  379. package/validators/index.js.map +2 -2
  380. package/validators/types.d.ts +1 -1
  381. package/validators/utils/amka/index.js +36 -0
  382. package/{inputs/inputsScenarios → validators/utils/amka}/package.json +1 -1
  383. package/validators/utils/amka.d.ts +6 -0
  384. package/validators/utils/amka.js.map +7 -0
  385. package/validators/utils/date/index.js +26 -3
  386. package/validators/utils/date.d.ts +3 -3
  387. package/validators/utils/date.js.map +2 -2
  388. package/validators/utils/datetime/index.js +118 -24
  389. package/validators/utils/datetime.d.ts +3 -3
  390. package/validators/utils/datetime.js.map +2 -2
  391. package/validators/utils/file/index.js +30 -17
  392. package/validators/utils/file.d.ts +2 -2
  393. package/validators/utils/file.js.map +2 -2
  394. package/validators/utils/iban.d.ts +2 -2
  395. package/validators/utils/iban.js.map +1 -1
  396. package/validators/utils/image.d.ts +2 -2
  397. package/validators/utils/image.js.map +1 -1
  398. package/validators/utils/index.d.ts +3 -2
  399. package/validators/utils/index.js +4 -1
  400. package/validators/utils/index.js.map +2 -2
  401. package/validators/utils/int.d.ts +1 -1
  402. package/validators/utils/int.js.map +1 -1
  403. package/validators/utils/number.d.ts +1 -1
  404. package/validators/utils/number.js.map +1 -1
  405. package/validators/utils/otp.d.ts +2 -2
  406. package/validators/utils/otp.js.map +1 -1
  407. package/validators/utils/phone.d.ts +2 -2
  408. package/validators/utils/phone.js.map +1 -1
  409. package/validators/utils/postal_code.d.ts +2 -2
  410. package/validators/utils/postal_code.js.map +1 -1
  411. package/validators/utils/text_limit.d.ts +2 -2
  412. package/validators/utils/text_limit.js.map +1 -1
  413. package/Field/utils/calculateField/index.js +0 -27
  414. package/Field/utils/calculateField.d.ts +0 -2
  415. package/Field/utils/calculateField.js.map +0 -7
  416. package/Field/utils/index.js.map +0 -7
  417. package/FieldArray/FormDialog.d.ts +0 -53
  418. package/FieldArray/FormDialog.js.map +0 -7
  419. package/FormBuilder/index.test.d.ts +0 -1
  420. package/FormBuilder/interaction.test.d.ts +0 -1
  421. package/FormBuilder/scenarios.test.d.ts +0 -88
  422. package/MultiplicityField/index.test.d.ts +0 -1
  423. package/Questions/index.spec.d.ts +0 -1
  424. package/Questions/index.test.d.ts +0 -1
  425. package/cjs/Field/utils/calculateField/index.js +0 -50
  426. package/cjs/Field/utils/calculateField.js.map +0 -7
  427. package/cjs/Field/utils/index.js.map +0 -7
  428. package/cjs/FieldArray/FormDialog.js.map +0 -7
  429. package/cjs/inputs/Input/inputsInputScenarios/index.js +0 -439
  430. package/cjs/inputs/Input/inputsInputScenarios.js.map +0 -7
  431. package/cjs/inputs/inputsScenarios/index.js +0 -533
  432. package/cjs/inputs/inputsScenarios.js.map +0 -7
  433. package/cjs/locales/el.js.map +0 -7
  434. package/inputs/AutoCompleteInput/index.test.d.ts +0 -1
  435. package/inputs/Checkboxes/index.test.d.ts +0 -1
  436. package/inputs/DateInput/index.test.d.ts +0 -1
  437. package/inputs/DateTimeInput/index.test.d.ts +0 -1
  438. package/inputs/FileInput/index.test.d.ts +0 -1
  439. package/inputs/ImageInput/index.test.d.ts +0 -1
  440. package/inputs/Input/index.test.d.ts +0 -1
  441. package/inputs/Input/inputsInputScenarios/index.js +0 -406
  442. package/inputs/Input/inputsInputScenarios.d.ts +0 -57
  443. package/inputs/Input/inputsInputScenarios.js.map +0 -7
  444. package/inputs/Label/index.test.d.ts +0 -1
  445. package/inputs/OtpInput/index.test.d.ts +0 -1
  446. package/inputs/Radio/index.test.d.ts +0 -1
  447. package/inputs/Select/index.test.d.ts +0 -1
  448. package/inputs/inputsScenarios/index.js +0 -499
  449. package/inputs/inputsScenarios.d.ts +0 -296
  450. package/inputs/inputsScenarios.js.map +0 -7
  451. package/locales/el/index.js +0 -6
  452. package/locales/el.d.ts +0 -2
  453. package/locales/el.js.map +0 -7
  454. package/src/Field/utils/calculateField.ts +0 -49
  455. package/src/FieldArray/FormDialog.tsx +0 -378
  456. package/src/inputs/Input/inputsInputScenarios.ts +0 -404
  457. package/src/inputs/inputsScenarios.ts +0 -496
  458. package/src/locales/el.ts +0 -3
  459. /package/{FieldArray/index.test.d.ts → hooks/__tests__/utils.spec.d.ts} +0 -0
package/src/types.tsx CHANGED
@@ -1,11 +1,11 @@
1
- import { UseFormReturn, UseFormProps } from 'react-hook-form';
2
- import {
3
- FieldComponentRegistry,
1
+ import type { UseFormReturn, UseFormProps, ErrorOption } from 'react-hook-form';
2
+ import type {
4
3
  FieldLabelProps,
5
4
  FieldSpec,
6
5
  FormData,
7
6
  } from '@digigov/form/Field/types';
8
- import { ValidatorSchema } from '@digigov/form/validators/types';
7
+ import type { FieldComponentRegistry } from '@digigov/form/inputs/registry';
8
+ import type { ValidatorSchema } from '@digigov/form/validators/types';
9
9
  export * from '@digigov/form/Field/types';
10
10
  export interface FieldError {
11
11
  message: string;
@@ -18,6 +18,11 @@ export interface FieldsetSpec {
18
18
  body?: React.ReactNode;
19
19
  }
20
20
 
21
+ export type registerFieldFocus = (
22
+ fieldName: string,
23
+ element: HTMLElement
24
+ ) => (name: string) => void;
25
+
21
26
  export interface FormContextProps {
22
27
  fieldsetsMap?: Record<string, FieldsetSpec>;
23
28
  fieldsMap: Record<string, FieldSpec>;
@@ -29,14 +34,16 @@ export interface FormContextProps {
29
34
  getFieldState: UseFormReturn['getFieldState'];
30
35
  setValue: UseFormReturn['setValue'];
31
36
  getValues: UseFormReturn['getValues'];
37
+ getValuesFromParentForm?: UseFormReturn['getValues'];
32
38
  unregister: UseFormReturn['unregister'];
33
39
  formState: UseFormReturn['formState'];
34
40
  reset: UseFormReturn['reset'];
35
41
  resetField: UseFormReturn['resetField'];
36
42
  registerField: (field: FieldSpec) => void;
43
+ registerFieldFocus: registerFieldFocus;
37
44
  errors: UseFormReturn['formState']['errors'];
38
45
  componentRegistry?: FieldComponentRegistry;
39
- submit: () => Promise<void>;
46
+ submit: () => Promise<void> | void;
40
47
  }
41
48
 
42
49
  export interface FormBuilderProps {
@@ -54,6 +61,7 @@ export interface FormBuilderProps {
54
61
  componentRegistry?: FieldComponentRegistry;
55
62
  grid?: boolean;
56
63
  controlledFieldsOnly?: boolean;
64
+ errors?: ErrorOption;
57
65
  }
58
66
 
59
67
  export interface FormBaseProps
package/src/utils.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { validateFieldsNatively } from '@hookform/resolvers';
2
- import { appendErrors, FieldError } from 'react-hook-form';
3
- import * as Yup from 'yup';
2
+ import type { FieldError } from 'react-hook-form';
3
+ import { appendErrors } from 'react-hook-form';
4
+ import type * as Yup from 'yup';
4
5
 
5
6
  /**
6
7
  * Why `path!` ? because it could be `undefined` in some case
@@ -13,6 +14,7 @@ const parseErrorSchema = (
13
14
  return (error.inner || []).reduce<Record<string, FieldError>>(
14
15
  (previous, error) => {
15
16
  error.path = error.path?.replace(/\[([0-9]+)\]/g, '.$1');
17
+ // error.path = error.path?.replace(/\["(.*?)"\]/g, '$1');
16
18
  if (!previous[error.path!]) {
17
19
  previous[error.path!] = { message: error.message, type: error.type! };
18
20
  }
@@ -37,6 +39,26 @@ const parseErrorSchema = (
37
39
  {}
38
40
  );
39
41
  };
42
+ function isPlainObject(obj) {
43
+ return (
44
+ typeof obj === 'object' &&
45
+ obj !== null &&
46
+ Object.prototype.toString.call(obj) === '[object Object]'
47
+ );
48
+ }
49
+ function flattenObject(obj, prefix = '') {
50
+ return Object.keys(obj).reduce((acc, key) => {
51
+ const prefixedKey = prefix ? `${prefix}.${key}` : key;
52
+
53
+ if (isPlainObject(obj[key])) {
54
+ Object.assign(acc, flattenObject(obj[key], prefixedKey));
55
+ } else {
56
+ acc[prefixedKey] = obj[key];
57
+ }
58
+
59
+ return acc;
60
+ }, {});
61
+ }
40
62
 
41
63
  export const yupResolver =
42
64
  (schema: any, schemaOptions: any = {}, resolverOptions: any = {}) =>
@@ -51,7 +73,7 @@ export const yupResolver =
51
73
  const result = await schema[
52
74
  resolverOptions.mode === 'sync' ? 'validateSync' : 'validate'
53
75
  ](
54
- values,
76
+ flattenObject(values),
55
77
  Object.assign({ abortEarly: false }, schemaOptions, { context })
56
78
  );
57
79
 
@@ -67,13 +89,13 @@ export const yupResolver =
67
89
  throw e;
68
90
  }
69
91
 
70
- const parsed = parseErrorSchema(
71
- e,
72
- !options.shouldUseNativeValidation && options.criteriaMode === 'all'
73
- );
74
92
  return {
75
93
  values: {},
76
- errors: parsed,
94
+ errors: parseErrorSchema(
95
+ e,
96
+ !options.shouldUseNativeValidation && options.criteriaMode === 'all'
97
+ ),
98
+ options,
77
99
  };
78
100
  }
79
101
  };
@@ -1,16 +1,18 @@
1
- import { MutableRefObject, useMemo } from 'react';
1
+ import type { MutableRefObject } from 'react';
2
+ import { useMemo } from 'react';
2
3
  import * as yup from 'yup';
3
- import { AnyObjectSchema, StringSchema } from 'yup';
4
- import { RequiredArraySchema } from 'yup/lib/array';
5
- import Lazy from 'yup/lib/Lazy';
6
- import { MixedSchema } from 'yup/lib/mixed';
7
- import { TypeOfShape, AssertsShape } from 'yup/lib/object';
8
- import { AnyObject } from 'yup/lib/types';
9
- import { FieldSpec } from '@digigov/form/types';
10
- import { ValidatorSchema } from '@digigov/form/validators/types';
4
+ import type { AnyObjectSchema, StringSchema } from 'yup';
5
+ import type { RequiredArraySchema } from 'yup/lib/array';
6
+ import type Lazy from 'yup/lib/Lazy';
7
+ import type { MixedSchema } from 'yup/lib/mixed';
8
+ import type { TypeOfShape, AssertsShape } from 'yup/lib/object';
9
+ import type { AnyObject } from 'yup/lib/types';
10
+ import type { FieldSpec } from '@digigov/form/types';
11
+ import type { ValidatorSchema } from '@digigov/form/validators/types';
11
12
  import {
12
13
  getYupObjectShape,
13
14
  AFM_VALIDATOR,
15
+ AMKA_VALIDATOR,
14
16
  FILE_MAX_SIZE_VALIDATOR,
15
17
  IBAN_VALIDATOR,
16
18
  OTP_VALIDATOR,
@@ -30,13 +32,15 @@ import {
30
32
  import { INT_VALIDATOR } from '@digigov/form/validators/utils/int';
31
33
  import { NUMBER_VALIDATOR } from '@digigov/form/validators/utils/number';
32
34
 
33
- export const getYUPTypeMap = (): Record<string, any> => {
35
+ export const getYUPTypeMap = (
36
+ validatorRegistry?: Record<string, any>
37
+ ): Record<string, any> => {
34
38
  const yupTypeMap = {
35
39
  file: (field): MixedSchema => {
36
40
  return yup
37
41
  .mixed()
38
42
  .transform((value) => {
39
- if (!value.length) {
43
+ if (!value || value.length === 0) {
40
44
  return null;
41
45
  }
42
46
  return value;
@@ -81,10 +85,13 @@ export const getYUPTypeMap = (): Record<string, any> => {
81
85
  if (typeof field.extra.of === 'object') {
82
86
  // else if the field is an object then it is a scalar type
83
87
  // eg. number, string etc.
88
+ if (field.required) {
89
+ field.extra.min = 1;
90
+ }
84
91
  let arrayValidator = yup
85
92
  .array()
86
- .of(yupTypeMap[field.extra.of.type](field.extra.of))
87
- .required(field.required);
93
+ .nullable()
94
+ .of(yupTypeMap[field.extra.of.type](field.extra.of));
88
95
  if (field.extra.length)
89
96
  arrayValidator = arrayValidator.length(field.extra.length, {
90
97
  key: 'form.error.array.length',
@@ -133,6 +140,10 @@ export const getYUPTypeMap = (): Record<string, any> => {
133
140
  field.trim
134
141
  ? yup.string().trim().test(AFM_VALIDATOR)
135
142
  : yup.string().test(AFM_VALIDATOR),
143
+ amka: (field): yup.StringSchema =>
144
+ field.trim
145
+ ? yup.string().trim().test(AMKA_VALIDATOR)
146
+ : yup.string().test(AMKA_VALIDATOR),
136
147
  uuid4: (field): yup.StringSchema =>
137
148
  field.trim
138
149
  ? yup.string().trim().test(UUID4_VALIDATOR)
@@ -215,6 +226,7 @@ export const getYUPTypeMap = (): Record<string, any> => {
215
226
  }
216
227
  return yup.string().test(DATETIME_VALIDATOR);
217
228
  },
229
+ ...validatorRegistry,
218
230
  };
219
231
  return yupTypeMap;
220
232
  };
@@ -226,7 +238,7 @@ export function useValidationSchema(
226
238
  validatorRegistry?: Record<string, ValidatorSchema[]>
227
239
  ): Lazy<any, unknown> | AnyObjectSchema | void {
228
240
  return useMemo(() => {
229
- const yupTypeMap = getYUPTypeMap();
241
+ const yupTypeMap = getYUPTypeMap(validatorRegistry);
230
242
  return getYupObjectShape(fields, yupTypeMap, validatorRegistry);
231
- }, []);
243
+ }, [fields, validatorRegistry]);
232
244
  }
@@ -1,2 +1,2 @@
1
- import * as yup from 'yup';
1
+ import type * as yup from 'yup';
2
2
  export type ValidatorSchema = yup.TestConfig;
@@ -0,0 +1,39 @@
1
+ function digitSum(number) {
2
+ const sum = number > 9 ? 1 : 0;
3
+ return sum + (number % 10);
4
+ }
5
+
6
+ export function validateAMKA(amka: string): boolean {
7
+ // Validate that the last digit is the correct check digit (created using the
8
+ // Luhn algorithm https://en.wikipedia.org/wiki/Luhn_algorithm).
9
+ amka = String(amka);
10
+ const checkDigitIndex = amka.length - 1;
11
+ let sum = 0;
12
+ amka
13
+ .substring(0, checkDigitIndex)
14
+ .split('')
15
+ .reverse()
16
+ .forEach(function (value, index) {
17
+ const weight = ((index + 1) % 2) + 1;
18
+ sum += digitSum(parseInt(value, 10) * weight);
19
+ });
20
+ const sumMod10 = sum % 10;
21
+ if (sumMod10 === 0) {
22
+ return amka.substring(checkDigitIndex) === '0';
23
+ } else {
24
+ return amka.substring(checkDigitIndex) === 10 - sumMod10 + '';
25
+ }
26
+ }
27
+
28
+ export const AMKA_VALIDATOR = {
29
+ name: 'amka-validator',
30
+ message: 'form.error.amka',
31
+ test: (value): boolean => {
32
+ if (!value) return true;
33
+ const AMKA_REGEX = /^[0-9]{11}$/;
34
+ if (!AMKA_REGEX.test(value) || value === '00000000000') {
35
+ return false;
36
+ }
37
+ return validateAMKA(value);
38
+ },
39
+ };
@@ -1,20 +1,24 @@
1
1
  import dayjs from 'dayjs';
2
2
  import customParseFormat from 'dayjs/plugin/customParseFormat';
3
- import { FieldSpec } from '@digigov/form/types';
4
- import { ValidatorSchema } from '@digigov/form/validators/types';
3
+ import type { FieldSpec } from '@digigov/form/types';
4
+ import type { ValidatorSchema } from '@digigov/form/validators/types';
5
5
 
6
6
  dayjs.extend(customParseFormat);
7
7
 
8
8
  const VALID_DATE_FORMATS = ['DD/MM/YYYY'];
9
9
  const DATE_CACHE = {};
10
+ const onlyNumbersRegex = /^\d+$/;
10
11
 
11
12
  const getDate = (v: string) => {
12
13
  return DATE_CACHE[v] ? DATE_CACHE[v] : dayjs(v, VALID_DATE_FORMATS, true);
13
14
  };
14
15
 
16
+ const getDaysInMonth = (month: number, year: number): number => {
17
+ return dayjs(`${year}-${month}-01`).daysInMonth(); // e.g. 29 for Feb 2024
18
+ };
19
+
15
20
  // Function to check partial date completion
16
21
  const checkPartialDate = (value: string) => {
17
- console.log("value.split('/')", value.split('/'));
18
22
  const [day, month, year] = value.split('/');
19
23
  if (day && !month && !year) {
20
24
  return 'form.error.date.invalid_month_year';
@@ -33,9 +37,29 @@ const checkPartialDate = (value: string) => {
33
37
  }
34
38
  if (!day && month && year) {
35
39
  return 'form.error.date.invalid_day';
36
- } else {
37
- return 'form.error.date.invalid';
38
40
  }
41
+ if (day && month) {
42
+ const dayNum = parseInt(day);
43
+ const monthNum = parseInt(month);
44
+ const validYear = onlyNumbersRegex.test(year) ? year : undefined;
45
+ if (!validYear || year.length < 4) {
46
+ return 'form.error.date.invalid';
47
+ }
48
+ const yearNum = parseInt(validYear);
49
+ const maxDay = getDaysInMonth(monthNum, yearNum);
50
+ if (dayNum < 1 || dayNum > maxDay) {
51
+ return {
52
+ key: 'form.error.date.invalid_day_range',
53
+ context: {
54
+ maxDay: maxDay,
55
+ },
56
+ };
57
+ }
58
+ if (monthNum < 1 || monthNum > 12) {
59
+ return 'form.error.datetime.invalid_month_range';
60
+ }
61
+ }
62
+ return 'form.error.date.invalid';
39
63
  };
40
64
 
41
65
  export const LATER_THAN_VALIDATOR = (field: FieldSpec): ValidatorSchema => {
@@ -96,7 +120,7 @@ export const EARLIER_THAN_VALIDATOR = (field: FieldSpec): ValidatorSchema => {
96
120
 
97
121
  export const DATE_VALIDATOR = {
98
122
  name: 'date-validator',
99
- message: (v): string => {
123
+ message: (v): string | object => {
100
124
  return checkPartialDate(v.value);
101
125
  },
102
126
  test: function (value: string) {
@@ -1,12 +1,13 @@
1
1
  import dayjs from 'dayjs';
2
2
  import customParseFormat from 'dayjs/plugin/customParseFormat';
3
- import { FieldSpec } from '@digigov/form/types';
4
- import { ValidatorSchema } from '@digigov/form/validators/types';
3
+ import type { FieldSpec } from '@digigov/form/types';
4
+ import type { ValidatorSchema } from '@digigov/form/validators/types';
5
5
 
6
6
  dayjs.extend(customParseFormat);
7
7
 
8
8
  const VALID_DATETIME_FORMATS = ['DD/MM/YYYY HH:mm'];
9
9
  const DATETIME_CACHE = {};
10
+ const onlyNumbersRegex = /^\d+$/;
10
11
 
11
12
  const getDateTime = (v: string) => {
12
13
  return DATETIME_CACHE[v]
@@ -14,54 +15,145 @@ const getDateTime = (v: string) => {
14
15
  : dayjs(v, VALID_DATETIME_FORMATS, true);
15
16
  };
16
17
 
17
- // Function to check partial datetime completion
18
+ const getDaysInMonth = (month: number, year: number): number => {
19
+ return dayjs(`${year}-${month}-01`).daysInMonth(); // e.g. 29 for Feb 2024
20
+ };
21
+
18
22
  const checkPartialDateTime = (value: string) => {
19
23
  const [datePart, timePart] = value.split(' ');
20
- const [day, month, year] = datePart.split('/');
21
- const [hours, minutes] = timePart ? timePart.split(':') : [null, null];
24
+ const [day, month, year] = datePart?.split('/') ?? [];
25
+ const [hours, minutes] = timePart?.split(':') ?? [];
26
+
27
+ const hasDay = Boolean(day);
28
+ const hasMonth = Boolean(month);
29
+ const hasYear = Boolean(year);
30
+ const hasHours = Boolean(hours);
31
+ const hasMinutes = Boolean(minutes);
22
32
 
23
- // Check date part first
24
- if (day && !month && !year) {
33
+ if (hasDay && !hasMonth && !hasYear && !hasHours && !hasMinutes) {
34
+ return 'form.error.datetime.invalid_month_year_hours_minutes';
35
+ }
36
+ if (!hasDay && hasMonth && !hasYear && !hasHours && !hasMinutes) {
37
+ return 'form.error.datetime.invalid_day_year_hours_minutes';
38
+ }
39
+ if (!hasDay && !hasMonth && hasYear && !hasHours && !hasMinutes) {
40
+ return 'form.error.datetime.invalid_day_month_hours_minutes';
41
+ }
42
+ if (hasDay && hasMonth && !hasYear && !hasHours && !hasMinutes) {
43
+ return 'form.error.datetime.invalid_year_hours_minutes';
44
+ }
45
+ if (hasDay && !hasMonth && hasYear && !hasHours && !hasMinutes) {
46
+ return 'form.error.datetime.invalid_month_hours_minutes';
47
+ }
48
+ if (!hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
49
+ return 'form.error.datetime.invalid_day_hours_minutes';
50
+ }
51
+ if (hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
52
+ return 'form.error.datetime.invalid__hours_minutes';
53
+ }
54
+ if (hasDay && hasMonth && hasYear && hasHours && !hasMinutes) {
55
+ return 'form.error.datetime.invalid_minutes';
56
+ }
57
+ if (hasDay && hasMonth && hasYear && !hasHours && hasMinutes) {
58
+ return 'form.error.datetime.invalid_hours';
59
+ }
60
+ if (hasDay && !hasMonth && !hasYear && hasHours && !hasMinutes) {
61
+ return 'form.error.datetime.invalid_month_year_minutes';
62
+ }
63
+ if (hasDay && !hasMonth && !hasYear && !hasHours && hasMinutes) {
64
+ return 'form.error.datetime.invalid_month_year_hours';
65
+ }
66
+ if (hasDay && !hasMonth && !hasYear && hasHours && hasMinutes) {
25
67
  return 'form.error.datetime.invalid_month_year';
26
68
  }
27
- if (!day && month && !year) {
69
+ if (!hasDay && hasMonth && !hasYear && hasHours && !hasMinutes) {
70
+ return 'form.error.datetime.invalid_day_year_minutes';
71
+ }
72
+ if (!hasDay && hasMonth && !hasYear && !hasHours && hasMinutes) {
73
+ return 'form.error.datetime.invalid_day_year_hours';
74
+ }
75
+ if (!hasDay && hasMonth && !hasYear && hasHours && hasMinutes) {
28
76
  return 'form.error.datetime.invalid_day_year';
29
77
  }
30
- if (!day && !month && year) {
78
+ if (!hasDay && !hasMonth && hasYear && hasHours && !hasMinutes) {
79
+ return 'form.error.datetime.invalid_day_month_minutes';
80
+ }
81
+ if (!hasDay && !hasMonth && hasYear && !hasHours && hasMinutes) {
82
+ return 'form.error.datetime.invalid_day_month_hours';
83
+ }
84
+ if (!hasDay && !hasMonth && hasYear && hasHours && hasMinutes) {
31
85
  return 'form.error.datetime.invalid_day_month';
32
86
  }
33
- if (day && month && !year) {
87
+ if (!hasDay && !hasMonth && !hasYear && hasHours && hasMinutes) {
88
+ return 'form.error.datetime.invalid_day_month_year';
89
+ }
90
+ if (!hasDay && !hasMonth && !hasYear && !hasHours && hasMinutes) {
91
+ return 'form.error.datetime.invalid_day_month_year_hours';
92
+ }
93
+ if (hasDay && hasMonth && !hasYear && hasHours && !hasMinutes) {
94
+ return 'form.error.datetime.invalid_year_minutes';
95
+ }
96
+ if (hasDay && hasMonth && !hasYear && !hasHours && hasMinutes) {
97
+ return 'form.error.datetime.invalid_year_hours';
98
+ }
99
+ if (hasDay && hasMonth && !hasYear && hasHours && hasMinutes) {
34
100
  return 'form.error.datetime.invalid_year';
35
101
  }
36
- if (day && !month && year) {
102
+ if (hasDay && !hasMonth && hasYear && hasHours && !hasMinutes) {
103
+ return 'form.error.datetime.invalid_month_minutes';
104
+ }
105
+ if (hasDay && !hasMonth && hasYear && !hasHours && hasMinutes) {
106
+ return 'form.error.datetime.invalid_month_hours';
107
+ }
108
+ if (hasDay && !hasMonth && hasYear && hasHours && hasMinutes) {
37
109
  return 'form.error.datetime.invalid_month';
38
110
  }
39
- if (!day && month && year) {
111
+ if (!hasDay && hasMonth && hasYear && hasHours && !hasMinutes) {
112
+ return 'form.error.datetime.invalid_day_minutes';
113
+ }
114
+ if (!hasDay && hasMonth && hasYear && !hasHours && hasMinutes) {
115
+ return 'form.error.datetime.invalid_day_hours';
116
+ }
117
+ if (!hasDay && hasMonth && hasYear && hasHours && hasMinutes) {
40
118
  return 'form.error.datetime.invalid_day';
41
119
  }
42
- // If date is complete, check time part
43
- if (day && month && year) {
44
- if (hours && !minutes) {
45
- return 'form.error.datetime.invalid_minutes';
120
+ if (!hasDay && !hasMonth && !hasYear && hasHours && !hasMinutes) {
121
+ return 'form.error.datetime.invalid_day_month_year_minutes';
122
+ }
123
+ if (hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
124
+ return 'form.error.datetime.invalid_hours_minutes';
125
+ }
126
+ if (day && month) {
127
+ const dayNum = parseInt(day);
128
+ const monthNum = parseInt(month);
129
+ const validYear = onlyNumbersRegex.test(year) ? year : undefined;
130
+ if (!validYear || year.length < 4) {
131
+ return 'form.error.datetime.invalid';
46
132
  }
47
- if (!hours && minutes) {
48
- return 'form.error.datetime.invalid_hours';
133
+ const yearNum = parseInt(validYear);
134
+ const maxDay = getDaysInMonth(monthNum, yearNum);
135
+ if (dayNum < 1 || dayNum > maxDay) {
136
+ return {
137
+ key: 'form.error.datetime.invalid_day_range',
138
+ context: {
139
+ maxDay: maxDay,
140
+ },
141
+ };
49
142
  }
50
- if (!hours && !minutes) {
51
- return 'form.error.datetime.invalid';
143
+ if (monthNum < 1 || monthNum > 12) {
144
+ return 'form.error.datetime.invalid_month_range';
145
+ }
146
+ }
147
+ if (hours && minutes) {
148
+ const hoursNum = parseInt(hours);
149
+ const minutesNum = parseInt(minutes);
150
+ if (hoursNum < 0 || hoursNum > 23) {
151
+ return 'form.error.datetime.invalid_hours_range';
52
152
  }
53
- if (hours && minutes) {
54
- const hoursNum = parseInt(hours);
55
- const minutesNum = parseInt(minutes);
56
- if (hoursNum < 0 || hoursNum > 23) {
57
- return 'form.error.datetime.invalid_hours_range';
58
- }
59
- if (minutesNum < 0 || minutesNum > 59) {
60
- return 'form.error.datetime.invalid_minutes_range';
61
- }
153
+ if (minutesNum < 0 || minutesNum > 59) {
154
+ return 'form.error.datetime.invalid_minutes_range';
62
155
  }
63
156
  }
64
-
65
157
  return 'form.error.datetime.invalid';
66
158
  };
67
159
 
@@ -119,7 +211,7 @@ export const EARLIER_THAN_DATETIME_VALIDATOR = (
119
211
 
120
212
  export const DATETIME_VALIDATOR = {
121
213
  name: 'datetime-validator',
122
- message: (v): string => {
214
+ message: (v): string | object => {
123
215
  return checkPartialDateTime(v.value);
124
216
  },
125
217
  test: function (value: string) {
@@ -1,27 +1,41 @@
1
- import { FieldSpec } from '@digigov/form/types';
2
- import { ValidatorSchema } from '@digigov/form/validators/types';
1
+ import type { FieldSpec } from '@digigov/form/types';
2
+ import type { ValidatorSchema } from '@digigov/form/validators/types';
3
3
 
4
4
  const DEFAULT_FILE_MAX_SIZE = 10000000;
5
5
 
6
- export const FILE_MAX_SIZE_VALIDATOR = (field: FieldSpec): ValidatorSchema => ({
7
- name: 'file-max-size-validator',
8
- message: {
9
- key:
10
- field.type === 'file' ? 'form.error.file_size' : 'form.error.image_size',
11
- context: {
12
- maxSizeToMb:
13
- (field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE) / 1000000,
6
+ export const FILE_MAX_SIZE_VALIDATOR = (field: FieldSpec): ValidatorSchema => {
7
+ const maxSizeInBytes = field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE;
8
+ let maxSizeTransformed = maxSizeInBytes / (1024 * 1024); // In MB
9
+ let maxSizeText = 'MB';
10
+ if (Math.round(maxSizeTransformed) === 0) {
11
+ maxSizeTransformed = Math.round(maxSizeInBytes / 1024);
12
+ maxSizeText = 'KB';
13
+ }
14
+ if (Math.round(maxSizeTransformed) === 0) {
15
+ maxSizeTransformed = maxSizeInBytes;
16
+ maxSizeText = 'Bytes';
17
+ }
18
+ return {
19
+ name: 'file-max-size-validator',
20
+ message: {
21
+ key:
22
+ field.type === 'file'
23
+ ? 'form.error.file_size'
24
+ : 'form.error.image_size',
25
+ context: {
26
+ maxSize: `${maxSizeTransformed} ${maxSizeText}`,
27
+ },
14
28
  },
15
- },
16
- test: (value: File[]): boolean => {
17
- if (value) {
18
- for (const file of value) {
19
- const maxSize = field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE;
20
- if (file.size > maxSize) {
21
- return false;
29
+ test: (value: File[]): boolean => {
30
+ if (value) {
31
+ for (const file of Array.from(value)) {
32
+ const maxSize = field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE;
33
+ if (file.size > maxSize) {
34
+ return false;
35
+ }
22
36
  }
23
37
  }
24
- }
25
- return true;
26
- },
27
- });
38
+ return true;
39
+ },
40
+ };
41
+ };
@@ -1,5 +1,5 @@
1
- import { FieldSpec } from '@digigov/form/types';
2
- import { ValidatorSchema } from '@digigov/form/validators/types';
1
+ import type { FieldSpec } from '@digigov/form/types';
2
+ import type { ValidatorSchema } from '@digigov/form/validators/types';
3
3
  export function validateIban(value: string, countryCode: string): boolean {
4
4
  value = value.replace(/\s/g, '').replace(/-/g, '');
5
5
  if (value.match(/^[0-9]*$/i)) {
@@ -1,5 +1,5 @@
1
- import { FieldSpec } from '@digigov/form/types';
2
- import { ValidatorSchema } from '@digigov/form/validators/types';
1
+ import type { FieldSpec } from '@digigov/form/types';
2
+ import type { ValidatorSchema } from '@digigov/form/validators/types';
3
3
 
4
4
  const DEFAULT_IMAGE_MAX_HEIGHT_SIZE = 2000;
5
5
  const DEFAULT_IMAGE_MAX_WIDTH_SIZE = 2000;
@@ -1,8 +1,9 @@
1
1
  import * as yup from 'yup';
2
- import { FieldSpec } from '@digigov/form/types';
3
- import { ValidatorSchema } from '@digigov/form/validators/types';
2
+ import type { FieldSpec } from '@digigov/form/types';
3
+ import type { ValidatorSchema } from '@digigov/form/validators/types';
4
4
 
5
5
  export * from '@digigov/form/validators/utils/afm';
6
+ export * from '@digigov/form/validators/utils/amka';
6
7
  export * from '@digigov/form/validators/utils/file';
7
8
  export * from '@digigov/form/validators/utils/iban';
8
9
  export * from '@digigov/form/validators/utils/otp';
@@ -98,7 +99,9 @@ export function getYupObjectShape(
98
99
 
99
100
  return yup.lazy(function () {
100
101
  const fieldSchemas = computeShape(
101
- Object.values(fields.current),
102
+ Object.values(fields.current).filter(
103
+ (f: FieldSpec) => !f.key.includes('.')
104
+ ) as FieldSpec[],
102
105
  yupTypeMap,
103
106
  validatorRegistry
104
107
  );
@@ -1,4 +1,4 @@
1
- import { ValidatorSchema } from '@digigov/form/validators/types';
1
+ import type { ValidatorSchema } from '@digigov/form/validators/types';
2
2
 
3
3
  export function validateIntNumber(number: number): boolean {
4
4
  if (number === undefined) {
@@ -1,4 +1,4 @@
1
- import { ValidatorSchema } from '@digigov/form/validators/types';
1
+ import type { ValidatorSchema } from '@digigov/form/validators/types';
2
2
 
3
3
  export function validateNumber(number: number): boolean {
4
4
  return !Number.isNaN(number);
@@ -1,5 +1,5 @@
1
- import { FieldSpec } from '@digigov/form/types';
2
- import { ValidatorSchema } from '@digigov/form/validators/types';
1
+ import type { FieldSpec } from '@digigov/form/types';
2
+ import type { ValidatorSchema } from '@digigov/form/validators/types';
3
3
  export function validateOtp(value: string, maxLength: number): boolean {
4
4
  if (value.length === maxLength) {
5
5
  return true;
@@ -1,5 +1,5 @@
1
- import { FieldSpec } from '@digigov/form/types';
2
- import { ValidatorSchema } from '@digigov/form/validators/types';
1
+ import type { FieldSpec } from '@digigov/form/types';
2
+ import type { ValidatorSchema } from '@digigov/form/validators/types';
3
3
 
4
4
  export type PhoneNumberType = 'landline' | 'mobile' | null;
5
5
  // add more countries from here libphonenumber-js/metadata.full.json