@ukhomeoffice/cop-react-form-renderer 5.0.0-alpha → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (277) hide show
  1. package/dist/components/CheckYourAnswers/Answer.js +18 -7
  2. package/dist/components/CheckYourAnswers/Answer.test.js +137 -0
  3. package/dist/components/CheckYourAnswers/CheckYourAnswers.js +70 -46
  4. package/dist/components/CheckYourAnswers/CheckYourAnswers.stories.mdx +410 -0
  5. package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +551 -0
  6. package/dist/components/CollectionPage/CollectionPage.js +15 -10
  7. package/dist/components/CollectionPage/CollectionPage.test.js +382 -0
  8. package/dist/components/FormComponent/Collection.js +91 -48
  9. package/dist/components/FormComponent/Collection.scss +2 -1
  10. package/dist/components/FormComponent/Collection.test.js +807 -0
  11. package/dist/components/FormComponent/Container.js +35 -16
  12. package/dist/components/FormComponent/Container.test.js +370 -0
  13. package/dist/components/FormComponent/FormComponent.js +39 -13
  14. package/dist/components/FormComponent/FormComponent.stories.mdx +184 -0
  15. package/dist/components/FormComponent/FormComponent.test.js +226 -0
  16. package/dist/components/FormComponent/helpers/addLabel.js +5 -4
  17. package/dist/components/FormComponent/helpers/getComponentFieldSet.js +16 -0
  18. package/dist/components/FormComponent/helpers/getComponentFieldSet.test.js +29 -0
  19. package/dist/components/FormComponent/helpers/index.js +8 -1
  20. package/dist/components/FormPage/FormPage.js +69 -30
  21. package/dist/components/FormPage/FormPage.stories.mdx +155 -0
  22. package/dist/components/FormPage/FormPage.test.js +330 -0
  23. package/dist/components/FormRenderer/FormRenderer.js +142 -228
  24. package/dist/components/FormRenderer/FormRenderer.stories.mdx +183 -0
  25. package/dist/components/FormRenderer/FormRenderer.test.js +968 -0
  26. package/dist/components/FormRenderer/handlers/index.js +1 -2
  27. package/dist/components/FormRenderer/handlers/navigate.js +3 -1
  28. package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.js +35 -14
  29. package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.test.js +88 -5
  30. package/dist/components/FormRenderer/helpers/getCYA.js +11 -2
  31. package/dist/components/FormRenderer/helpers/getNextPageId.js +13 -7
  32. package/dist/components/FormRenderer/helpers/getRelevantPages.js +10 -2
  33. package/dist/components/FormRenderer/helpers/getRelevantPages.test.js +1 -1
  34. package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +2 -2
  35. package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +6 -2
  36. package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +171 -51
  37. package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.test.js +307 -24
  38. package/dist/components/FormRenderer/helpers/index.js +1 -2
  39. package/dist/components/FormRenderer/onCYAAction.js +108 -0
  40. package/dist/components/FormRenderer/onCYAAction.test.js +583 -0
  41. package/dist/components/FormRenderer/onPageAction.js +145 -0
  42. package/dist/components/FormRenderer/onPageAction.test.js +678 -0
  43. package/dist/components/FormRenderer/onTaskAction.js +48 -0
  44. package/dist/components/FormRenderer/onTaskAction.test.js +217 -0
  45. package/dist/components/PageActions/ActionButton.js +0 -3
  46. package/dist/components/PageActions/ActionButton.test.js +93 -0
  47. package/dist/components/PageActions/PageActions.js +2 -2
  48. package/dist/components/PageActions/PageActions.stories.mdx +74 -0
  49. package/dist/components/PageActions/PageActions.test.js +132 -0
  50. package/dist/components/SummaryList/GroupAction.js +2 -2
  51. package/dist/components/SummaryList/GroupAction.test.js +80 -0
  52. package/dist/components/SummaryList/RowAction.js +2 -2
  53. package/dist/components/SummaryList/RowAction.test.js +80 -0
  54. package/dist/components/SummaryList/SummaryList.js +29 -12
  55. package/dist/components/SummaryList/SummaryList.scss +19 -0
  56. package/dist/components/SummaryList/SummaryList.stories.mdx +90 -0
  57. package/dist/components/SummaryList/SummaryList.test.js +400 -0
  58. package/dist/components/SummaryList/SummaryListHeadingRow.js +30 -0
  59. package/dist/components/SummaryList/SummaryListRow.js +5 -2
  60. package/dist/components/SummaryList/helpers/getGroupActionAttributes.js +2 -1
  61. package/dist/components/SummaryList/helpers/getRowActionAttributes.js +2 -1
  62. package/dist/components/TaskList/Task.js +3 -3
  63. package/dist/components/TaskList/Task.test.js +167 -0
  64. package/dist/components/TaskList/TaskList.js +73 -22
  65. package/dist/components/TaskList/TaskList.stories.mdx +164 -0
  66. package/dist/components/TaskList/TaskList.test.js +389 -0
  67. package/dist/components/TaskList/TaskState.js +2 -2
  68. package/dist/components/TaskList/TaskState.test.js +86 -0
  69. package/dist/components/index.js +14 -0
  70. package/dist/context/HooksContext/HooksContext.js +72 -8
  71. package/dist/context/HooksContext/HooksContext.test.js +44 -0
  72. package/dist/context/ValidationContext/ValidationContext.js +38 -28
  73. package/dist/context/ValidationContext/ValidationContext.test.js +84 -0
  74. package/dist/hooks/useAxios.js +10 -12
  75. package/dist/hooks/useGetRequest.js +48 -49
  76. package/dist/hooks/useRefData.js +7 -4
  77. package/dist/index.js +34 -1
  78. package/dist/json/addressDetails.json +149 -0
  79. package/dist/json/areYouACivilServant.json +7 -0
  80. package/dist/json/firstForm.json +94 -0
  81. package/dist/json/grade.json +108 -0
  82. package/dist/json/group.data.json +21 -0
  83. package/dist/json/group.json +402 -0
  84. package/dist/json/groupOfRow.json +137 -0
  85. package/dist/json/groupOfRowData.json +15 -0
  86. package/dist/json/port.json +346 -0
  87. package/dist/json/saveAndContinue.json +98 -0
  88. package/dist/json/sublocation.json +859 -0
  89. package/dist/json/taskList.json +265 -0
  90. package/dist/json/team.json +17351 -0
  91. package/dist/json/terminal.json +81 -0
  92. package/dist/json/userProfile.data.json +21 -0
  93. package/dist/json/userProfile.json +276 -0
  94. package/dist/models/ComponentTypes.js +8 -0
  95. package/dist/models/PageAction.js +4 -1
  96. package/dist/models/TaskStates.js +10 -2
  97. package/dist/models/index.js +16 -1
  98. package/dist/setupTests.js +46 -0
  99. package/dist/utils/CheckYourAnswers/getCYAAction.js +5 -5
  100. package/dist/utils/CheckYourAnswers/getCYAAction.test.js +121 -0
  101. package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.js +6 -2
  102. package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.test.js +71 -0
  103. package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.js +6 -2
  104. package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.test.js +55 -0
  105. package/dist/utils/CheckYourAnswers/getCYARow.js +14 -11
  106. package/dist/utils/CheckYourAnswers/getCYARow.test.js +291 -0
  107. package/dist/utils/CheckYourAnswers/getCYARowForGroup.js +4 -1
  108. package/dist/utils/CheckYourAnswers/getCYARowForGroup.test.js +70 -0
  109. package/dist/utils/CheckYourAnswers/getCYARowsForCollection.js +15 -10
  110. package/dist/utils/CheckYourAnswers/getCYARowsForCollection.test.js +288 -0
  111. package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +94 -36
  112. package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +414 -0
  113. package/dist/utils/CheckYourAnswers/getCYARowsForContainer.js +21 -7
  114. package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +486 -0
  115. package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +11 -3
  116. package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +346 -0
  117. package/dist/utils/CheckYourAnswers/showComponentCYA.js +19 -3
  118. package/dist/utils/CheckYourAnswers/showComponentCYA.test.js +143 -0
  119. package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +5 -1
  120. package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.test.js +40 -0
  121. package/dist/utils/CollectionPage/getCollectionPageActiveIndex.test.js +53 -0
  122. package/dist/utils/CollectionPage/mergeCollectionPages.js +25 -17
  123. package/dist/utils/CollectionPage/mergeCollectionPages.test.js +130 -0
  124. package/dist/utils/Component/addShowWhen.js +44 -0
  125. package/dist/utils/Component/addShowWhen.test.js +216 -0
  126. package/dist/utils/Component/applyToComponentTree.js +71 -0
  127. package/dist/utils/Component/applyToComponentTree.test.js +127 -0
  128. package/dist/utils/Component/cleanAttributes.js +8 -2
  129. package/dist/utils/Component/cleanAttributes.test.js +68 -0
  130. package/dist/utils/Component/elevateNestedComponents.js +4 -1
  131. package/dist/utils/Component/elevateNestedComponents.test.js +122 -0
  132. package/dist/utils/Component/getComponent.js +80 -11
  133. package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +4 -4
  134. package/dist/utils/Component/getComponentTests/getComponent.calculation.test.js +25 -24
  135. package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +66 -5
  136. package/dist/utils/Component/getComponentTests/getComponent.date.test.js +2 -2
  137. package/dist/utils/Component/getComponentTests/getComponent.details.test.js +9 -7
  138. package/dist/utils/Component/getComponentTests/getComponent.email.test.js +3 -3
  139. package/dist/utils/Component/getComponentTests/getComponent.file.test.js +3 -3
  140. package/dist/utils/Component/getComponentTests/getComponent.list.test.js +44 -0
  141. package/dist/utils/Component/getComponentTests/{getComponent.textarea.test.js → getComponent.multifile.test.js} +29 -21
  142. package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +159 -83
  143. package/dist/utils/Component/getComponentTests/getComponent.paragraph.test.js +43 -0
  144. package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +3 -3
  145. package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +55 -5
  146. package/dist/utils/Component/getComponentTests/getComponent.select.test.js +3 -9
  147. package/dist/utils/Component/getComponentTests/getComponent.text.test.js +3 -3
  148. package/dist/utils/Component/getComponentTests/getComponent.textArea.test.js +109 -0
  149. package/dist/utils/Component/getComponentTests/getComponent.time.test.js +7 -7
  150. package/dist/utils/Component/getDefaultValue.js +4 -1
  151. package/dist/utils/Component/getDefaultValue.test.js +50 -0
  152. package/dist/utils/Component/index.js +2 -0
  153. package/dist/utils/Component/isEditable.js +2 -2
  154. package/dist/utils/Component/isEditable.test.js +43 -0
  155. package/dist/utils/Component/optionIsSelected.js +22 -0
  156. package/dist/utils/Component/optionIsSelected.test.js +42 -0
  157. package/dist/utils/Component/setupContainerComponentsPath.js +40 -0
  158. package/dist/utils/Component/setupContainerComponentsPath.test.js +78 -0
  159. package/dist/utils/Component/showComponent.test.js +156 -0
  160. package/dist/utils/Component/wrapInFormGroup.js +1 -1
  161. package/dist/utils/Condition/meetsAllConditions.js +1 -1
  162. package/dist/utils/Condition/meetsAllConditions.test.js +61 -0
  163. package/dist/utils/Condition/meetsCondition.js +74 -4
  164. package/dist/utils/Condition/meetsCondition.test.js +763 -0
  165. package/dist/utils/Condition/meetsOneCondition.js +1 -1
  166. package/dist/utils/Condition/meetsOneCondition.test.js +100 -0
  167. package/dist/utils/Condition/setupConditions.js +6 -3
  168. package/dist/utils/Condition/setupConditions.test.js +33 -0
  169. package/dist/utils/Container/getEditableComponents.test.js +135 -0
  170. package/dist/utils/Container/setupNesting.js +21 -2
  171. package/dist/utils/Container/setupNesting.test.js +145 -0
  172. package/dist/utils/Container/showContainer.test.js +178 -0
  173. package/dist/utils/Data/applyFormula.js +20 -11
  174. package/dist/utils/Data/applyFormula.test.js +263 -0
  175. package/dist/utils/Data/getAutocompleteSource.js +6 -2
  176. package/dist/utils/Data/getAutocompleteSource.test.js +352 -0
  177. package/dist/utils/Data/getDataPath.test.js +48 -0
  178. package/dist/utils/Data/getOptions.js +17 -3
  179. package/dist/utils/Data/getOptions.test.js +140 -0
  180. package/dist/utils/Data/getSourceData.js +2 -2
  181. package/dist/utils/Data/getSourceData.test.js +153 -0
  182. package/dist/utils/Data/refDataToOptions.js +4 -1
  183. package/dist/utils/Data/refDataToOptions.test.js +196 -0
  184. package/dist/utils/Data/setDataItem.test.js +110 -0
  185. package/dist/utils/Data/setupFormData.js +39 -16
  186. package/dist/utils/Data/setupFormData.test.js +410 -0
  187. package/dist/utils/Data/setupRefDataUrlForComponent.js +4 -1
  188. package/dist/utils/Data/setupRefDataUrlForComponent.test.js +131 -0
  189. package/dist/utils/FormPage/applyConditionalProperties.js +35 -0
  190. package/dist/utils/FormPage/applyConditionalProperties.test.js +61 -0
  191. package/dist/utils/FormPage/getFormPage.js +5 -2
  192. package/dist/utils/FormPage/getFormPage.test.js +206 -0
  193. package/dist/utils/FormPage/getFormPages.js +4 -1
  194. package/dist/utils/FormPage/getFormPages.test.js +97 -0
  195. package/dist/utils/FormPage/getPageActions.js +8 -4
  196. package/dist/utils/FormPage/getPageActions.test.js +114 -0
  197. package/dist/utils/FormPage/getParagraphFromText.test.js +27 -0
  198. package/dist/utils/FormPage/index.js +2 -0
  199. package/dist/utils/FormPage/showFormPage.js +2 -2
  200. package/dist/utils/FormPage/showFormPage.test.js +180 -0
  201. package/dist/utils/FormPage/showFormPageCYA.js +1 -0
  202. package/dist/utils/FormPage/showFormPageCYA.test.js +28 -0
  203. package/dist/utils/FormPage/useComponent.js +29 -14
  204. package/dist/utils/FormPage/useComponent.test.js +167 -0
  205. package/dist/utils/Format/formatData.test.js +45 -0
  206. package/dist/utils/Format/formatDataForComponent.js +2 -1
  207. package/dist/utils/Format/formatDataForComponent.test.js +142 -0
  208. package/dist/utils/Format/formatDataForForm.js +4 -1
  209. package/dist/utils/Format/formatDataForForm.test.js +81 -0
  210. package/dist/utils/Format/formatDataForPage.test.js +99 -0
  211. package/dist/utils/Hub/getFormHub.test.js +105 -0
  212. package/dist/utils/Meta/documents/getDocuments.test.js +4 -1
  213. package/dist/utils/Meta/documents/index.js +2 -2
  214. package/dist/utils/Meta/documents/setDocumentsForField.js +31 -0
  215. package/dist/utils/Meta/documents/setDocumentsForField.test.js +59 -0
  216. package/dist/utils/Operate/checkValueIsTruthy.test.js +42 -0
  217. package/dist/utils/Operate/getFirstOf.js +31 -0
  218. package/dist/utils/Operate/getFirstOf.test.js +86 -0
  219. package/dist/utils/Operate/getIndexOfMatchingValueIn.test.js +163 -0
  220. package/dist/utils/Operate/persistValueInFormData.js +2 -1
  221. package/dist/utils/Operate/persistValueInFormData.test.js +115 -0
  222. package/dist/utils/Operate/runPageOperations.js +3 -1
  223. package/dist/utils/Operate/runPageOperations.test.js +105 -0
  224. package/dist/utils/Operate/setValueInFormData.test.js +44 -0
  225. package/dist/utils/Operate/shouldRun.js +16 -13
  226. package/dist/utils/Operate/shouldRun.test.js +66 -0
  227. package/dist/utils/Validate/additional/conditionallyRequired.js +24 -0
  228. package/dist/utils/Validate/additional/conditionallyRequired.test.js +73 -0
  229. package/dist/utils/Validate/additional/index.js +13 -4
  230. package/dist/utils/Validate/additional/mustBeAfter.js +8 -6
  231. package/dist/utils/Validate/additional/mustBeAfter.test.js +15 -1
  232. package/dist/utils/Validate/additional/mustBeBefore.js +9 -5
  233. package/dist/utils/Validate/additional/mustBeBefore.test.js +14 -0
  234. package/dist/utils/Validate/additional/mustBeEarlierDateTime.js +1 -1
  235. package/dist/utils/Validate/additional/mustBeEarlierDateTime.test.js +6 -3
  236. package/dist/utils/Validate/additional/mustBeGreaterThan.js +22 -0
  237. package/dist/utils/Validate/additional/mustBeGreaterThan.test.js +56 -0
  238. package/dist/utils/Validate/additional/mustBeInTheFuture.js +1 -1
  239. package/dist/utils/Validate/additional/mustBeInThePast.js +5 -5
  240. package/dist/utils/Validate/additional/mustBeLessThan.js +7 -6
  241. package/dist/utils/Validate/additional/mustBeLessThan.test.js +11 -1
  242. package/dist/utils/Validate/additional/mustBeNumbersOnly.js +9 -5
  243. package/dist/utils/Validate/additional/mustBeNumbersOnly.test.js +10 -2
  244. package/dist/utils/Validate/additional/mustEnterAtLeastOne.js +1 -0
  245. package/dist/utils/Validate/additional/mustEnterAtLeastOne.test.js +4 -1
  246. package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.js +19 -0
  247. package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.test.js +36 -0
  248. package/dist/utils/Validate/additional/mustSelectOnlyOne.js +29 -0
  249. package/dist/utils/Validate/additional/mustSelectOnlyOne.test.js +52 -0
  250. package/dist/utils/Validate/additional/utils.js +18 -18
  251. package/dist/utils/Validate/index.js +6 -0
  252. package/dist/utils/Validate/validateCollection.js +20 -5
  253. package/dist/utils/Validate/validateCollection.test.js +125 -0
  254. package/dist/utils/Validate/validateComponent.js +36 -20
  255. package/dist/utils/Validate/validateComponent.test.js +365 -0
  256. package/dist/utils/Validate/validateContainer.js +9 -3
  257. package/dist/utils/Validate/validateContainer.test.js +75 -0
  258. package/dist/utils/Validate/validateDate.js +4 -3
  259. package/dist/utils/Validate/validateDate.test.js +114 -0
  260. package/dist/utils/Validate/validateEmail.js +14 -1
  261. package/dist/utils/Validate/validateEmail.test.js +74 -0
  262. package/dist/utils/Validate/validateMultifile.js +32 -0
  263. package/dist/utils/Validate/validateMultifile.test.js +47 -0
  264. package/dist/utils/Validate/validatePage.js +12 -6
  265. package/dist/utils/Validate/validatePage.test.js +472 -0
  266. package/dist/utils/Validate/validateRegex.js +2 -5
  267. package/dist/utils/Validate/validateRegex.test.js +42 -0
  268. package/dist/utils/Validate/validateRequired.js +2 -4
  269. package/dist/utils/Validate/validateRequired.test.js +63 -0
  270. package/dist/utils/Validate/validateTextArea.js +37 -0
  271. package/dist/utils/Validate/validateTextArea.test.js +42 -0
  272. package/dist/utils/Validate/validateTime.js +2 -2
  273. package/dist/utils/Validate/validateTime.test.js +59 -0
  274. package/dist/utils/index.js +4 -1
  275. package/package.json +35 -50
  276. package/dist/utils/Meta/documents/setDocumentForField.js +0 -29
  277. package/dist/utils/Meta/documents/setDocumentForField.test.js +0 -49
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ var _mustHaveLessThanDecimalPlaces = _interopRequireDefault(require("./mustHaveLessThanDecimalPlaces"));
4
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
5
+ describe('utils', function () {
6
+ describe('Validate', function () {
7
+ describe('additional', function () {
8
+ describe('mustHaveLessThanDecimalPlaces', function () {
9
+ test('should return false given a number with more than the allowed number of decimal places', function () {
10
+ var result = (0, _mustHaveLessThanDecimalPlaces.default)('999999999.9999', {
11
+ maxDecimals: 3
12
+ });
13
+ expect(result).toEqual(false);
14
+ });
15
+ test('should return true given a number with less than the allowed number of decimal places', function () {
16
+ var result = (0, _mustHaveLessThanDecimalPlaces.default)('999999999.99', {
17
+ maxDecimals: 3
18
+ });
19
+ expect(result).toEqual(true);
20
+ });
21
+ test('should return true given a number with no decimal places', function () {
22
+ var result = (0, _mustHaveLessThanDecimalPlaces.default)('999999999', {
23
+ maxDecimals: 3
24
+ });
25
+ expect(result).toEqual(true);
26
+ });
27
+ test('should return true given nothing', function () {
28
+ var result = (0, _mustHaveLessThanDecimalPlaces.default)(undefined, {
29
+ maxDecimals: 3
30
+ });
31
+ expect(result).toEqual(true);
32
+ });
33
+ });
34
+ });
35
+ });
36
+ });
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ /**
8
+ * Additional validator for the Container component type.
9
+ * @param {object} data the form data
10
+ * @param {object} component the container component
11
+ * @returns true if the user has only provided a value for one of the components in the container, otherwise false.
12
+ */
13
+ var mustSelectOnlyOne = function mustSelectOnlyOne(data, _, component) {
14
+ var _component$components;
15
+ var valueCount = (_component$components = component.components) === null || _component$components === void 0 ? void 0 : _component$components.reduce(function (acc, inner) {
16
+ var _data$component$id;
17
+ if ((_data$component$id = data[component.id]) !== null && _data$component$id !== void 0 && _data$component$id[inner.id]) {
18
+ // Account for checkboxes that the user may have unselected
19
+ if (Array.isArray(data[component.id][inner.id]) && data[component.id][inner.id].length === 0) {
20
+ return acc;
21
+ }
22
+ return acc + 1;
23
+ }
24
+ return acc;
25
+ }, 0);
26
+ return valueCount < 2;
27
+ };
28
+ var _default = mustSelectOnlyOne;
29
+ exports.default = _default;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ var _mustSelectOnlyOne = _interopRequireDefault(require("./mustSelectOnlyOne"));
4
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
5
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
6
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
7
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
8
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
9
+ describe('utils', function () {
10
+ describe('Validate', function () {
11
+ describe('additional', function () {
12
+ describe('mustSelectOnlyOne', function () {
13
+ var CONTAINER_ID = 'containerId';
14
+ var COMPONENT = {
15
+ id: CONTAINER_ID,
16
+ type: 'container',
17
+ components: [{
18
+ id: 'alpha'
19
+ }, {
20
+ id: 'bravo'
21
+ }, {
22
+ id: 'charlie'
23
+ }]
24
+ };
25
+ test('should return true if all components are empty', function () {
26
+ var DATA = {};
27
+ expect((0, _mustSelectOnlyOne.default)(DATA, {}, COMPONENT)).toEqual(true);
28
+ });
29
+ test('should return true if one component has data', function () {
30
+ var DATA = _defineProperty({}, CONTAINER_ID, {
31
+ alpha: 'text'
32
+ });
33
+ expect((0, _mustSelectOnlyOne.default)(DATA, {}, COMPONENT)).toEqual(true);
34
+ });
35
+ test('should return false if more than one component has data', function () {
36
+ var DATA = _defineProperty({}, CONTAINER_ID, {
37
+ alpha: 'text',
38
+ bravo: 'test'
39
+ });
40
+ expect((0, _mustSelectOnlyOne.default)(DATA, {}, COMPONENT)).toEqual(false);
41
+ });
42
+ test('should return true if more than one component has data but one is an empty array', function () {
43
+ var DATA = _defineProperty({}, CONTAINER_ID, {
44
+ alpha: 'text',
45
+ bravo: []
46
+ });
47
+ expect((0, _mustSelectOnlyOne.default)(DATA, {}, COMPONENT)).toEqual(true);
48
+ });
49
+ });
50
+ });
51
+ });
52
+ });
@@ -7,12 +7,28 @@ exports.formattedTime = exports.formatString = exports.DATE_FORMAT = void 0;
7
7
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
8
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
9
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
11
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
10
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
11
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
12
12
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
13
  var isNumeric = function isNumeric(value) {
14
14
  return /^-?\d+$/.test(value);
15
15
  };
16
+
17
+ /**
18
+
19
+ /**
20
+ * Prepends a leading zero if the 'date component' parameter contains only a single digit.
21
+ * if the parameter contains more than one digit it is returned unchanged.
22
+ * If the parameter contains a non-numeric value it returned as an empty string.
23
+ * @param {string} dateComponent - the value representing a day or month.
24
+ * @returns the value (appended with a leading zero, if the value passed in was a single digit)
25
+ */
26
+ var formatInTwoDigits = function formatInTwoDigits(dateComponent) {
27
+ if (isNumeric(dateComponent)) {
28
+ return dateComponent.padStart(2, '0');
29
+ }
30
+ return '';
31
+ };
16
32
  var formatString = function formatString(date) {
17
33
  var _date$split = date.split('-'),
18
34
  _date$split2 = _slicedToArray(_date$split, 3),
@@ -29,22 +45,6 @@ var formattedTime = function formattedTime(time) {
29
45
  minute = _time$split2[1];
30
46
  return "".concat(formatInTwoDigits(hour), ":").concat(formatInTwoDigits(minute));
31
47
  };
32
-
33
- /**
34
-
35
- /**
36
- * Prepends a leading zero if the 'date component' parameter contains only a single digit.
37
- * if the parameter contains more than one digit it is returned unchanged.
38
- * If the parameter contains a non-numeric value it returned as an empty string.
39
- * @param {string} dateComponent - the value representing a day or month.
40
- * @returns the value (appended with a leading zero, if the value passed in was a single digit)
41
- */
42
48
  exports.formattedTime = formattedTime;
43
- var formatInTwoDigits = function formatInTwoDigits(dateComponent) {
44
- if (isNumeric(dateComponent)) {
45
- return dateComponent.padStart(2, '0');
46
- }
47
- return '';
48
- };
49
49
  var DATE_FORMAT = 'DD-MM-YYYY';
50
50
  exports.DATE_FORMAT = DATE_FORMAT;
@@ -5,22 +5,28 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _validateComponent = _interopRequireDefault(require("./validateComponent"));
8
+ var _validateContainer = _interopRequireDefault(require("./validateContainer"));
8
9
  var _validateDate = _interopRequireDefault(require("./validateDate"));
9
10
  var _validateEmail = _interopRequireDefault(require("./validateEmail"));
11
+ var _validateMultifile = _interopRequireDefault(require("./validateMultifile"));
10
12
  var _validatePage = _interopRequireDefault(require("./validatePage"));
11
13
  var _validateRegex = _interopRequireDefault(require("./validateRegex"));
12
14
  var _validateRequired = _interopRequireDefault(require("./validateRequired"));
15
+ var _validateTextArea = _interopRequireDefault(require("./validateTextArea"));
13
16
  var _validateTime = _interopRequireDefault(require("./validateTime"));
14
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
18
  // Local imports
16
19
 
17
20
  var Validate = {
18
21
  component: _validateComponent.default,
22
+ container: _validateContainer.default,
19
23
  email: _validateEmail.default,
20
24
  date: _validateDate.default,
25
+ multifile: _validateMultifile.default,
21
26
  page: _validatePage.default,
22
27
  regex: _validateRegex.default,
23
28
  required: _validateRequired.default,
29
+ textarea: _validateTextArea.default,
24
30
  time: _validateTime.default
25
31
  };
26
32
  var _default = Validate;
@@ -4,11 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+ var _copReactComponents = require("@ukhomeoffice/cop-react-components");
7
8
  var _validateContainer = _interopRequireDefault(require("./validateContainer"));
8
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
9
11
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
10
12
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
11
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
13
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
14
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
15
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
12
16
  /**
13
17
  * Validates all of the items within a collection.
14
18
  * @param {object} collection The collection to validate.
@@ -20,13 +24,24 @@ var validateCollection = function validateCollection(collection, items, formData
20
24
  var errors = [];
21
25
  if (collection && Array.isArray(collection.item) && Array.isArray(items)) {
22
26
  items.forEach(function (item, index) {
23
- var full_path = "".concat(collection.full_path || collection.fieldId, "[").concat(index, "]");
27
+ var labelCount = (collection.countOffset || 0) + index + 1;
28
+ var fullPath = "".concat(collection.full_path || collection.fieldId, "[").concat(index, "]");
24
29
  var container = {
25
- full_path: full_path,
30
+ full_path: fullPath,
26
31
  components: collection.item.map(function (component) {
27
- return _objectSpread(_objectSpread({}, component), {}, {
28
- full_path: "".concat(full_path, ".").concat(component.fieldId)
32
+ var newComponent = _objectSpread(_objectSpread({}, component), {}, {
33
+ full_path: "".concat(fullPath, ".").concat(component.fieldId)
29
34
  });
35
+ if (component.custom_errors && Array.isArray(component.custom_errors)) {
36
+ newComponent.custom_errors = component.custom_errors.map(function (error) {
37
+ return _objectSpread(_objectSpread({}, error), {}, {
38
+ message: _copReactComponents.Utils.interpolateString(index === 0 && error.firstOnlyMessage ? error.firstOnlyMessage : error.message, {
39
+ index: labelCount
40
+ })
41
+ });
42
+ });
43
+ }
44
+ return newComponent;
30
45
  })
31
46
  };
32
47
  errors.push((0, _validateContainer.default)(container, item, formData));
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+
3
+ var _models = require("../../models");
4
+ var _validateCollection = _interopRequireDefault(require("./validateCollection"));
5
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
7
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
9
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
10
+ describe('utils.Validate.Collection', function () {
11
+ var setup = function setup(id, type, label, required, item) {
12
+ return {
13
+ id: id,
14
+ fieldId: id,
15
+ type: type,
16
+ label: label,
17
+ required: required,
18
+ item: item
19
+ };
20
+ };
21
+ it('should return an empty array when the component is null', function () {
22
+ expect((0, _validateCollection.default)(null, [])).toEqual([]);
23
+ });
24
+ it('should return an empty array when the collection has an undefined item array', function () {
25
+ var ID = 'collection';
26
+ var LABEL = 'field';
27
+ var COLLECTION = setup(ID, _models.ComponentTypes.COLLECTION, LABEL, false, undefined);
28
+ expect((0, _validateCollection.default)(COLLECTION, [])).toEqual([]);
29
+ });
30
+ it('should return an empty array when the collection has an empty item array', function () {
31
+ var ID = 'collection';
32
+ var LABEL = 'field';
33
+ var COLLECTION = setup(ID, _models.ComponentTypes.COLLECTION, LABEL, false, []);
34
+ expect((0, _validateCollection.default)(COLLECTION, [])).toEqual([]);
35
+ });
36
+ it('should return an empty array when the collection has only valid items', function () {
37
+ var EMAIL_ID = 'email';
38
+ var EMAIL_LABEL = 'Email';
39
+ var EMAIL = setup(EMAIL_ID, _models.ComponentTypes.EMAIL, EMAIL_LABEL, false);
40
+ var ID = 'collection';
41
+ var LABEL = 'field';
42
+ var COLLECTION = setup(ID, _models.ComponentTypes.COLLECTION, LABEL, false, [EMAIL]);
43
+ var ITEMS = [_defineProperty({}, EMAIL_ID, 'alpha.bravo@homeoffice.gov.uk'), _defineProperty({}, EMAIL_ID, 'charlie.delta@homeoffice.gov.uk')];
44
+ expect((0, _validateCollection.default)(COLLECTION, ITEMS)).toEqual([]);
45
+ });
46
+ it('should return an array containing an error when the collection has an invalid first item', function () {
47
+ var EMAIL_ID = 'email';
48
+ var EMAIL_LABEL = 'Email';
49
+ var EMAIL = setup(EMAIL_ID, _models.ComponentTypes.EMAIL, EMAIL_LABEL, false);
50
+ var ID = 'container';
51
+ var LABEL = 'field';
52
+ var COLLECTION = setup(ID, _models.ComponentTypes.CONTAINER, LABEL, false, [EMAIL]);
53
+ var ITEMS = [_defineProperty({}, EMAIL_ID, 'alpha.bravo@digital.homeoffice.com'), _defineProperty({}, EMAIL_ID, 'alpha.bravo@digital.homeoffice.gov.uk')];
54
+ expect((0, _validateCollection.default)(COLLECTION, ITEMS)).toEqual([{
55
+ id: "".concat(ID, "[0].").concat(EMAIL_ID),
56
+ error: "Enter ".concat(EMAIL_LABEL.toLowerCase(), " in the correct format, like jane.doe@homeoffice.gov.uk")
57
+ }]);
58
+ });
59
+ it('should return an array containing an error when the collection has an invalid second item', function () {
60
+ var EMAIL_ID = 'email';
61
+ var EMAIL_LABEL = 'Email';
62
+ var EMAIL = setup(EMAIL_ID, _models.ComponentTypes.EMAIL, EMAIL_LABEL, false);
63
+ var ID = 'container';
64
+ var LABEL = 'field';
65
+ var COLLECTION = setup(ID, _models.ComponentTypes.CONTAINER, LABEL, false, [EMAIL]);
66
+ var ITEMS = [_defineProperty({}, EMAIL_ID, 'alpha.bravo@digital.homeoffice.gov.uk'), _defineProperty({}, EMAIL_ID, 'alpha.bravo@digital.homeoffice.com')];
67
+ expect((0, _validateCollection.default)(COLLECTION, ITEMS)).toEqual([{
68
+ id: "".concat(ID, "[1].").concat(EMAIL_ID),
69
+ error: "Enter ".concat(EMAIL_LABEL.toLowerCase(), " in the correct format, like jane.doe@homeoffice.gov.uk")
70
+ }]);
71
+ });
72
+ it('should correctly interpolate error messages using collection\'s index', function () {
73
+ var ID = 'container';
74
+ var LABEL = 'field';
75
+ var TYPE = 'autocomplete';
76
+ var ITEM = setup(ID, TYPE, LABEL, true, []);
77
+ ITEM.custom_errors = [{
78
+ "type": "required",
79
+ // eslint-disable-next-line no-template-curly-in-string
80
+ "message": "Test to check that ${index} is 1"
81
+ }];
82
+ var COLLECTION = setup(ID, _models.ComponentTypes.CONTAINER, LABEL, false, [ITEM]);
83
+ COLLECTION.countOffset = 0;
84
+ expect((0, _validateCollection.default)(COLLECTION, ITEM.custom_errors)).toEqual([{
85
+ error: "Test to check that 1 is 1",
86
+ id: "".concat(ID, "[0].").concat(COLLECTION.type)
87
+ }]);
88
+ });
89
+ it('should correctly display firstOnlyMessage error message', function () {
90
+ var ID = 'container';
91
+ var LABEL = 'field';
92
+ var TYPE = 'autocomplete';
93
+ var ITEM = setup(ID, TYPE, LABEL, true, []);
94
+ ITEM.custom_errors = [{
95
+ "type": "required",
96
+ // eslint-disable-next-line no-template-curly-in-string
97
+ "message": "Test to check that ${index} is 1",
98
+ "firstOnlyMessage": "Test for first message"
99
+ }];
100
+ var COLLECTION = setup(ID, _models.ComponentTypes.CONTAINER, LABEL, false, [ITEM]);
101
+ COLLECTION.countOffset = 0;
102
+ expect((0, _validateCollection.default)(COLLECTION, ITEM.custom_errors)).toEqual([{
103
+ error: "Test for first message",
104
+ id: "".concat(ID, "[0].").concat(COLLECTION.type)
105
+ }]);
106
+ });
107
+ it('should correctly display message if firstOnlyMessage is undefined', function () {
108
+ var ID = 'container';
109
+ var LABEL = 'field';
110
+ var TYPE = 'autocomplete';
111
+ var ITEM = setup(ID, TYPE, LABEL, true, []);
112
+ ITEM.custom_errors = [{
113
+ "type": "required",
114
+ // eslint-disable-next-line no-template-curly-in-string
115
+ "message": "Test to check that ${index} is 1",
116
+ "firstOnlyMessage": undefined
117
+ }];
118
+ var COLLECTION = setup(ID, _models.ComponentTypes.CONTAINER, LABEL, false, [ITEM]);
119
+ COLLECTION.countOffset = 0;
120
+ expect((0, _validateCollection.default)(COLLECTION, ITEM.custom_errors)).toEqual([{
121
+ error: "Test to check that 1 is 1",
122
+ id: "".concat(ID, "[0].").concat(COLLECTION.type)
123
+ }]);
124
+ });
125
+ });
@@ -5,14 +5,17 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _models = require("../../models");
8
+ var _optionIsSelected = _interopRequireDefault(require("../Component/optionIsSelected"));
8
9
  var _showComponent = _interopRequireDefault(require("../Component/showComponent"));
9
10
  var _additional = _interopRequireDefault(require("./additional"));
10
11
  var _validateCollection = _interopRequireDefault(require("./validateCollection"));
11
12
  var _validateContainer = _interopRequireDefault(require("./validateContainer"));
12
13
  var _validateDate = _interopRequireDefault(require("./validateDate"));
13
14
  var _validateEmail = _interopRequireDefault(require("./validateEmail"));
15
+ var _validateMultifile = _interopRequireDefault(require("./validateMultifile"));
14
16
  var _validateRegex = _interopRequireDefault(require("./validateRegex"));
15
17
  var _validateRequired = _interopRequireDefault(require("./validateRequired"));
18
+ var _validateTextArea = _interopRequireDefault(require("./validateTextArea"));
16
19
  var _validateTime = _interopRequireDefault(require("./validateTime"));
17
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
21
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
@@ -24,7 +27,6 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
24
27
  * @returns The first encountered error with the component.
25
28
  */
26
29
  var validateComponent = function validateComponent(component, outerData, formData) {
27
- var _component$data$optio;
28
30
  var fd = formData || outerData;
29
31
  if (!(0, _showComponent.default)(component, fd)) {
30
32
  return undefined;
@@ -32,8 +34,8 @@ var validateComponent = function validateComponent(component, outerData, formDat
32
34
  if (component.type === _models.ComponentTypes.CONTAINER) {
33
35
  return (0, _validateContainer.default)(component, outerData, fd);
34
36
  }
35
- var error = undefined;
36
- var properties = undefined;
37
+ var error;
38
+ var properties;
37
39
  var data = outerData && _typeof(outerData) === 'object' ? outerData : {};
38
40
  var value = data[component.fieldId];
39
41
  if (component.required) {
@@ -44,29 +46,43 @@ var validateComponent = function validateComponent(component, outerData, formDat
44
46
  case _models.ComponentTypes.COLLECTION:
45
47
  return (0, _validateCollection.default)(component, value, fd);
46
48
  case _models.ComponentTypes.EMAIL:
47
- error = (0, _validateEmail.default)(value, component.label);
49
+ error = (0, _validateEmail.default)(value, component.label, component.custom_errors);
48
50
  break;
49
51
  case _models.ComponentTypes.DATE:
50
52
  case _models.ComponentTypes.TIME:
51
- var validator = component.type === _models.ComponentTypes.DATE ? _validateDate.default : _validateTime.default;
52
- var _validator = validator(value),
53
- message = _validator.message,
54
- propsInError = _validator.propsInError;
55
- properties = propsInError;
56
- error = message;
57
- break;
53
+ {
54
+ var validator = component.type === _models.ComponentTypes.DATE ? _validateDate.default : _validateTime.default;
55
+ var _validator = validator(value),
56
+ message = _validator.message,
57
+ propsInError = _validator.propsInError;
58
+ properties = propsInError;
59
+ error = message;
60
+ break;
61
+ }
62
+ ;
63
+ case _models.ComponentTypes.CHECKBOXES:
58
64
  case _models.ComponentTypes.RADIOS:
59
- var nestedErrors = [];
60
- (_component$data$optio = component.data.options) === null || _component$data$optio === void 0 ? void 0 : _component$data$optio.forEach(function (option) {
61
- if (option.nested && formData[component.id] === option.value) {
62
- nestedErrors = nestedErrors.concat((0, _validateContainer.default)({
63
- components: option.nested
64
- }, formData));
65
+ {
66
+ var _component$data$optio;
67
+ var nestedErrors = [];
68
+ (_component$data$optio = component.data.options) === null || _component$data$optio === void 0 ? void 0 : _component$data$optio.forEach(function (option) {
69
+ if (option.nested && (0, _optionIsSelected.default)(formData[component.id], option)) {
70
+ nestedErrors = nestedErrors.concat((0, _validateContainer.default)({
71
+ components: option.nested
72
+ }, formData));
73
+ }
74
+ });
75
+ if (nestedErrors.length > 0) {
76
+ return nestedErrors;
65
77
  }
66
- });
67
- if (nestedErrors.length > 0) {
68
- return nestedErrors;
78
+ break;
69
79
  }
80
+ ;
81
+ case _models.ComponentTypes.MULTI_FILE:
82
+ error = (0, _validateMultifile.default)(value, component.custom_errors);
83
+ break;
84
+ case _models.ComponentTypes.TEXT_AREA:
85
+ error = (0, _validateTextArea.default)(component.label, value, component.showCharacterCount, component.custom_errors, component.maxLength);
70
86
  break;
71
87
  default:
72
88
  break;