@digigov/form 0.6.9 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -1
- package/Field/FieldBase.js +110 -0
- package/Field/{ConditionalField.js → FieldConditional.js} +9 -29
- package/Field/FieldContainer.js +62 -0
- package/Field/index.js +11 -251
- package/Field/types.js +5 -0
- package/Field/utils.js +146 -0
- package/Fieldset/FieldsetWithContext.js +63 -0
- package/Fieldset/index.js +4 -63
- package/Fieldset/types.js +5 -0
- package/FormBuilder.js +178 -0
- package/FormContext.js +14 -0
- package/Questions/Questions.js +105 -0
- package/Questions/QuestionsContext.js +20 -0
- package/Questions/Step/ReviewStep.js +11 -7
- package/Questions/Step/Step.js +93 -0
- package/Questions/Step/StepArrayReview.js +79 -0
- package/Questions/Step/StepContext.js +37 -0
- package/Questions/Step/StepDescription.js +2 -2
- package/Questions/Step/StepForm.js +10 -6
- package/Questions/Step/StepTitle.js +2 -2
- package/Questions/Step/getAddMoreFields.js +31 -0
- package/Questions/Step/index.js +81 -200
- package/Questions/Step/types.js +5 -0
- package/Questions/__snapshots__/index.spec.tsx.snap +461 -2499
- package/Questions/getNextStep.js +30 -0
- package/Questions/index.js +4 -150
- package/Questions/types.js +5 -0
- package/es/Field/FieldBase.js +93 -0
- package/es/Field/{ConditionalField.js → FieldConditional.js} +5 -28
- package/es/Field/FieldContainer.js +40 -0
- package/es/Field/index.js +8 -233
- package/es/Field/types.js +1 -0
- package/es/Field/utils.js +122 -0
- package/es/Fieldset/FieldsetWithContext.js +41 -0
- package/es/Fieldset/index.js +3 -51
- package/es/Fieldset/types.js +1 -0
- package/es/FormBuilder.js +148 -0
- package/es/FormContext.js +5 -0
- package/es/Questions/Questions.js +84 -0
- package/es/Questions/QuestionsContext.js +11 -0
- package/es/Questions/Step/ReviewStep.js +5 -3
- package/es/Questions/Step/Step.js +69 -0
- package/es/Questions/Step/StepArrayReview.js +50 -0
- package/es/Questions/Step/StepContext.js +27 -0
- package/es/Questions/Step/StepDescription.js +1 -1
- package/es/Questions/Step/StepForm.js +4 -2
- package/es/Questions/Step/StepTitle.js +1 -1
- package/es/Questions/Step/getAddMoreFields.js +22 -0
- package/es/Questions/Step/index.js +13 -165
- package/es/Questions/Step/types.js +1 -0
- package/es/Questions/__snapshots__/index.spec.tsx.snap +461 -2499
- package/es/Questions/getNextStep.js +23 -0
- package/es/Questions/index.js +2 -119
- package/es/Questions/index.spec.js +2 -1
- package/es/Questions/types.js +1 -0
- package/es/index.js +2 -153
- package/es/inputs/index.js +5 -4
- package/es/internal.js +31 -0
- package/es/types.js +1 -0
- package/es/utils.js +5 -3
- package/es/validators/index.js +155 -0
- package/es/validators/types.js +1 -0
- package/es/validators/utils/afm.js +35 -0
- package/es/validators/utils/file.js +52 -0
- package/es/validators/utils/iban.js +123 -0
- package/es/validators/utils/index.js +105 -0
- package/es/validators/utils/phone.js +122 -0
- package/es/validators/utils/postal_code.js +29 -0
- package/es/validators/utils/uuid4.js +20 -0
- package/{esm → es/validators}/validators.spec.js +1 -1
- package/esm/Field/FieldBase.js +93 -0
- package/esm/Field/{ConditionalField.js → FieldConditional.js} +5 -28
- package/esm/Field/FieldContainer.js +40 -0
- package/esm/Field/index.js +8 -233
- package/esm/Field/types.js +1 -0
- package/esm/Field/utils.js +122 -0
- package/esm/Fieldset/FieldsetWithContext.js +41 -0
- package/esm/Fieldset/index.js +3 -51
- package/esm/Fieldset/types.js +1 -0
- package/esm/FormBuilder.js +148 -0
- package/esm/FormContext.js +5 -0
- package/esm/Questions/Questions.js +84 -0
- package/esm/Questions/QuestionsContext.js +11 -0
- package/esm/Questions/Step/ReviewStep.js +5 -3
- package/esm/Questions/Step/Step.js +69 -0
- package/esm/Questions/Step/StepArrayReview.js +50 -0
- package/esm/Questions/Step/StepContext.js +27 -0
- package/esm/Questions/Step/StepDescription.js +1 -1
- package/esm/Questions/Step/StepForm.js +4 -2
- package/esm/Questions/Step/StepTitle.js +1 -1
- package/esm/Questions/Step/getAddMoreFields.js +22 -0
- package/esm/Questions/Step/index.js +13 -165
- package/esm/Questions/Step/types.js +1 -0
- package/esm/Questions/__snapshots__/index.spec.tsx.snap +461 -2499
- package/esm/Questions/getNextStep.js +23 -0
- package/esm/Questions/index.js +2 -119
- package/esm/Questions/index.spec.js +2 -1
- package/esm/Questions/types.js +1 -0
- package/esm/index.js +3 -154
- package/esm/inputs/index.js +5 -4
- package/esm/internal.js +31 -0
- package/esm/types.js +1 -0
- package/esm/utils.js +5 -3
- package/esm/validators/index.js +155 -0
- package/esm/validators/types.js +1 -0
- package/esm/validators/utils/afm.js +35 -0
- package/esm/validators/utils/file.js +52 -0
- package/esm/validators/utils/iban.js +123 -0
- package/esm/validators/utils/index.js +105 -0
- package/esm/validators/utils/phone.js +122 -0
- package/esm/validators/utils/postal_code.js +29 -0
- package/esm/validators/utils/uuid4.js +20 -0
- package/{es → esm/validators}/validators.spec.js +1 -1
- package/index.js +8 -191
- package/inputs/index.js +13 -5
- package/internal.js +356 -0
- package/libs/form/src/Field/FieldBase.d.ts +3 -0
- package/libs/form/src/Field/FieldConditional.d.ts +4 -0
- package/libs/form/src/Field/FieldContainer.d.ts +4 -0
- package/libs/form/src/Field/index.d.ts +1 -62
- package/libs/form/src/Field/types.d.ts +75 -0
- package/libs/form/src/Field/utils.d.ts +5 -0
- package/libs/form/src/Fieldset/FieldsetWithContext.d.ts +4 -0
- package/libs/form/src/Fieldset/index.d.ts +2 -12
- package/libs/form/src/Fieldset/types.d.ts +6 -0
- package/libs/form/src/FormBuilder.d.ts +5 -0
- package/libs/form/src/FormContext.d.ts +3 -0
- package/libs/form/src/Questions/Questions.d.ts +8 -0
- package/libs/form/src/Questions/QuestionsContext.d.ts +3 -0
- package/libs/form/src/Questions/Step/ReviewStep.d.ts +1 -0
- package/libs/form/src/Questions/Step/Step.d.ts +9 -0
- package/libs/form/src/Questions/Step/StepArrayReview.d.ts +4 -0
- package/libs/form/src/Questions/Step/StepContext.d.ts +4 -0
- package/libs/form/src/Questions/Step/StepForm.d.ts +2 -1
- package/libs/form/src/Questions/Step/getAddMoreFields.d.ts +3 -0
- package/libs/form/src/Questions/Step/index.d.ts +12 -47
- package/libs/form/src/Questions/Step/types.d.ts +31 -0
- package/libs/form/src/Questions/getNextStep.d.ts +2 -0
- package/libs/form/src/Questions/index.d.ts +1 -28
- package/libs/form/src/Questions/types.d.ts +19 -0
- package/libs/form/src/index.d.ts +2 -73
- package/libs/form/src/inputs/Checkboxes/index.d.ts +1 -1
- package/libs/form/src/inputs/DateInput/index.d.ts +1 -2
- package/libs/form/src/inputs/FileInput/index.d.ts +1 -1
- package/libs/form/src/inputs/Input/index.d.ts +1 -1
- package/libs/form/src/inputs/Label/index.d.ts +2 -1
- package/libs/form/src/inputs/Radio/index.d.ts +1 -1
- package/libs/form/src/inputs/Select/index.d.ts +1 -1
- package/libs/form/src/inputs/index.d.ts +4 -3
- package/libs/form/src/internal.d.ts +31 -0
- package/libs/form/src/types.d.ts +70 -0
- package/libs/form/src/validators/index.d.ts +8 -0
- package/libs/form/src/validators/types.d.ts +2 -0
- package/libs/form/src/validators/utils/afm.d.ts +6 -0
- package/libs/form/src/validators/utils/file.d.ts +1 -0
- package/libs/form/src/validators/utils/iban.d.ts +2 -0
- package/libs/form/src/validators/utils/index.d.ts +12 -0
- package/libs/form/src/validators/utils/phone.d.ts +9 -0
- package/libs/form/src/validators/utils/postal_code.d.ts +2 -0
- package/libs/form/src/validators/utils/uuid4.d.ts +6 -0
- package/libs/form/src/{validators.spec.d.ts → validators/validators.spec.d.ts} +0 -0
- package/libs/ui/src/core/Accordion/index.d.ts +3 -3
- package/libs/ui/src/core/Base/index.d.ts +3 -0
- package/libs/ui/src/core/Blockquote/index.d.ts +1 -1
- package/libs/ui/src/core/Button/BackButton.d.ts +1 -1
- package/libs/ui/src/core/Button/ButtonLink.d.ts +1 -1
- package/libs/ui/src/core/Button/index.d.ts +1 -1
- package/libs/ui/src/core/Divider/index.d.ts +1 -1
- package/libs/ui/src/core/Form/index.d.ts +3 -0
- package/libs/ui/src/core/Label/index.d.ts +4 -0
- package/libs/ui/src/core/Link/index.d.ts +1 -0
- package/libs/ui/src/core/NavList/NavHorizontal.d.ts +3 -0
- package/libs/ui/src/core/NavList/NavHorizontalList.d.ts +3 -0
- package/libs/ui/src/core/NavList/NavHorizontalListItem.d.ts +3 -0
- package/libs/ui/src/core/NavList/NavList.d.ts +1 -14
- package/libs/ui/src/core/NavList/NavListBase.d.ts +4 -0
- package/libs/ui/src/core/NavList/NavListItem.d.ts +1 -0
- package/libs/ui/src/core/NavList/NavListItemBase.d.ts +2 -1
- package/libs/ui/src/core/NavList/NavListSubMenu.d.ts +1 -1
- package/libs/ui/src/core/NavList/NavVertical.d.ts +3 -0
- package/libs/ui/src/core/NavList/NavVerticalItem.d.ts +3 -0
- package/libs/ui/src/core/NavList/index.d.ts +5 -0
- package/libs/ui/src/core/NavList/types.d.ts +14 -0
- package/libs/ui/src/core/SkipLink/index.d.ts +3 -0
- package/libs/ui/src/core/SvgIcon/index.d.ts +1 -0
- package/libs/ui/src/core/Table/TableFloatingScroll.d.ts +2 -0
- package/libs/ui/src/core/Table/index.d.ts +1 -0
- package/libs/ui/src/core/index.d.ts +4 -0
- package/libs/ui/src/layouts/Grid/index.d.ts +1 -0
- package/libs/ui/src/typography/Caption/index.d.ts +3 -2
- package/libs/ui/src/typography/Title/index.d.ts +2 -1
- package/libs-ui/react-core/src/Accordion/index.d.ts +3 -3
- package/libs-ui/react-core/src/AccordionControls/index.d.ts +3 -3
- package/libs-ui/react-core/src/AccordionSection/index.d.ts +3 -3
- package/libs-ui/react-core/src/AccordionSectionContent/index.d.ts +3 -3
- package/libs-ui/react-core/src/AccordionSectionHeader/index.d.ts +3 -3
- package/libs-ui/react-core/src/AccordionSectionSummary/index.d.ts +4 -3
- package/libs-ui/react-core/src/AccordionSectionSummaryHeading/index.d.ts +3 -3
- package/libs-ui/react-core/src/BackLink/index.d.ts +3 -3
- package/libs-ui/react-core/src/Base/index.d.ts +43 -0
- package/libs-ui/react-core/src/Blockquote/index.d.ts +3 -3
- package/libs-ui/react-core/src/Breadcrumbs/index.d.ts +3 -3
- package/libs-ui/react-core/src/BreadcrumbsList/index.d.ts +3 -3
- package/libs-ui/react-core/src/BreadcrumbsListItem/index.d.ts +3 -3
- package/libs-ui/react-core/src/Button/index.d.ts +3 -3
- package/libs-ui/react-core/src/ButtonGroup/index.d.ts +3 -3
- package/libs-ui/react-core/src/ButtonLink/index.d.ts +3 -3
- package/libs-ui/react-core/src/CallToAction/index.d.ts +1 -1
- package/libs-ui/react-core/src/Card/index.d.ts +3 -3
- package/libs-ui/react-core/src/CardAction/index.d.ts +3 -3
- package/libs-ui/react-core/src/CardHeading/index.d.ts +3 -3
- package/libs-ui/react-core/src/CardText/index.d.ts +3 -3
- package/libs-ui/react-core/src/CheckIcon/index.d.ts +15 -0
- package/libs-ui/react-core/src/Checkbox/index.d.ts +3 -3
- package/libs-ui/react-core/src/CheckboxItem/index.d.ts +3 -3
- package/libs-ui/react-core/src/Confirmation/index.d.ts +3 -3
- package/libs-ui/react-core/src/ConfirmationBody/index.d.ts +3 -3
- package/libs-ui/react-core/src/ConfirmationTitle/index.d.ts +3 -3
- package/libs-ui/react-core/src/DateInput/index.d.ts +3 -3
- package/libs-ui/react-core/src/DateInputItem/index.d.ts +3 -3
- package/libs-ui/react-core/src/Details/index.d.ts +3 -3
- package/libs-ui/react-core/src/DetailsContent/index.d.ts +3 -3
- package/libs-ui/react-core/src/DetailsSummary/index.d.ts +3 -3
- package/libs-ui/react-core/src/ErrorMessage/index.d.ts +3 -3
- package/libs-ui/react-core/src/ErrorSummary/index.d.ts +3 -3
- package/libs-ui/react-core/src/Field/index.d.ts +3 -3
- package/libs-ui/react-core/src/Fieldset/index.d.ts +3 -3
- package/libs-ui/react-core/src/FieldsetLegend/index.d.ts +3 -3
- package/libs-ui/react-core/src/FileUpload/index.d.ts +3 -3
- package/libs-ui/react-core/src/Form/index.d.ts +11 -0
- package/libs-ui/react-core/src/Grid/index.d.ts +3 -3
- package/libs-ui/react-core/src/Heading/index.d.ts +3 -3
- package/libs-ui/react-core/src/HeadingCaption/index.d.ts +3 -3
- package/libs-ui/react-core/src/Hidden/index.d.ts +3 -3
- package/libs-ui/react-core/src/Hint/index.d.ts +3 -3
- package/libs-ui/react-core/src/Label/index.d.ts +3 -3
- package/libs-ui/react-core/src/LabelTitle/index.d.ts +7 -7
- package/libs-ui/react-core/src/Link/index.d.ts +3 -3
- package/libs-ui/react-core/src/List/index.d.ts +3 -3
- package/libs-ui/react-core/src/ListItem/index.d.ts +3 -3
- package/libs-ui/react-core/src/NavHorizontal/index.d.ts +16 -0
- package/libs-ui/react-core/src/NavHorizontalList/index.d.ts +10 -0
- package/libs-ui/react-core/src/NavHorizontalListItem/index.d.ts +18 -0
- package/libs-ui/react-core/src/NavVertical/index.d.ts +11 -0
- package/libs-ui/react-core/src/NavVerticalItem/index.d.ts +14 -0
- package/libs-ui/react-core/src/NormalText/index.d.ts +3 -3
- package/libs-ui/react-core/src/NotificationBanner/index.d.ts +3 -3
- package/libs-ui/react-core/src/NotificationBannerContent/index.d.ts +3 -3
- package/libs-ui/react-core/src/NotificationBannerHeader/index.d.ts +3 -3
- package/libs-ui/react-core/src/NotificationBannerHeading/index.d.ts +3 -3
- package/libs-ui/react-core/src/NotificationBannerLink/index.d.ts +3 -3
- package/libs-ui/react-core/src/Paragraph/index.d.ts +3 -3
- package/libs-ui/react-core/src/PhaseBanner/index.d.ts +3 -3
- package/libs-ui/react-core/src/PhaseBannerHeaderContainer/index.d.ts +3 -3
- package/libs-ui/react-core/src/PhaseBannerTag/index.d.ts +3 -3
- package/libs-ui/react-core/src/PhaseBannerText/index.d.ts +3 -3
- package/libs-ui/react-core/src/Radio/index.d.ts +3 -3
- package/libs-ui/react-core/src/RadioItem/index.d.ts +3 -3
- package/libs-ui/react-core/src/SectionBreak/index.d.ts +3 -3
- package/libs-ui/react-core/src/Select/index.d.ts +3 -3
- package/libs-ui/react-core/src/SelectOption/index.d.ts +3 -3
- package/libs-ui/react-core/src/SkipLink/index.d.ts +10 -0
- package/libs-ui/react-core/src/SummaryList/index.d.ts +3 -3
- package/libs-ui/react-core/src/SummaryListItem/index.d.ts +3 -3
- package/libs-ui/react-core/src/SummaryListItemAction/index.d.ts +3 -3
- package/libs-ui/react-core/src/SummaryListItemKey/index.d.ts +3 -3
- package/libs-ui/react-core/src/SummaryListItemValue/index.d.ts +3 -3
- package/libs-ui/react-core/src/SvgIcon/index.d.ts +3 -3
- package/libs-ui/react-core/src/Table/index.d.ts +3 -3
- package/libs-ui/react-core/src/TableBody/index.d.ts +3 -3
- package/libs-ui/react-core/src/TableCaption/index.d.ts +3 -3
- package/libs-ui/react-core/src/TableContainer/index.d.ts +3 -3
- package/libs-ui/react-core/src/TableDataCell/index.d.ts +3 -3
- package/libs-ui/react-core/src/TableHead/index.d.ts +3 -3
- package/libs-ui/react-core/src/TableHeadCell/index.d.ts +3 -3
- package/libs-ui/react-core/src/TableNoDataRow/index.d.ts +3 -3
- package/libs-ui/react-core/src/TableRow/index.d.ts +3 -3
- package/libs-ui/react-core/src/Tabs/index.d.ts +3 -3
- package/libs-ui/react-core/src/TabsHeading/index.d.ts +3 -3
- package/libs-ui/react-core/src/TabsList/index.d.ts +3 -3
- package/libs-ui/react-core/src/TabsListItem/index.d.ts +3 -3
- package/libs-ui/react-core/src/TabsPanel/index.d.ts +3 -3
- package/libs-ui/react-core/src/TextArea/index.d.ts +3 -3
- package/libs-ui/react-core/src/TextInput/index.d.ts +3 -3
- package/libs-ui/react-core/src/UncheckIcon/index.d.ts +4 -4
- package/libs-ui/react-core/src/VisuallyHidden/index.d.ts +3 -3
- package/libs-ui/react-core/src/WarningText/index.d.ts +3 -3
- package/package.json +3 -2
- package/types.js +5 -0
- package/utils.js +6 -4
- package/validators/index.js +181 -0
- package/validators/types.js +5 -0
- package/validators/utils/afm.js +45 -0
- package/validators/utils/file.js +62 -0
- package/validators/utils/iban.js +134 -0
- package/validators/utils/index.js +210 -0
- package/validators/utils/phone.js +144 -0
- package/validators/utils/postal_code.js +40 -0
- package/validators/utils/uuid4.js +30 -0
- package/validators/validators.spec.js +88 -0
- package/es/validators.js +0 -626
- package/esm/validators.js +0 -626
- package/libs/form/src/Field/ConditionalField.d.ts +0 -17
- package/libs/form/src/validators.d.ts +0 -14
- package/validators.js +0 -662
- package/validators.spec.js +0 -88
package/esm/validators.js
DELETED
|
@@ -1,626 +0,0 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
-
|
|
4
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
5
|
-
|
|
6
|
-
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); }
|
|
7
|
-
|
|
8
|
-
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; }
|
|
9
|
-
|
|
10
|
-
import * as yup from 'yup';
|
|
11
|
-
import * as gPhoneNumber from 'google-libphonenumber';
|
|
12
|
-
import { useMemo } from 'react';
|
|
13
|
-
import dayjs from 'dayjs';
|
|
14
|
-
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
15
|
-
dayjs.extend(customParseFormat);
|
|
16
|
-
var DEFAULT_FILE_MAX_SIZE = 10000000;
|
|
17
|
-
export function validatePostalCode(number, countries) {
|
|
18
|
-
if (!countries) {
|
|
19
|
-
return false;
|
|
20
|
-
} else {
|
|
21
|
-
if (countries.length === 1 && countries[0].toUpperCase() === 'GR') {
|
|
22
|
-
// Greek postal code must be 5 digits long and shouldn't start with 0 or 9.
|
|
23
|
-
var CODE_REGEX = /^[12345678][0-9]{4}$/;
|
|
24
|
-
return CODE_REGEX.test(number);
|
|
25
|
-
} else {
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
export function validateAFM(afm) {
|
|
31
|
-
if (afm.length !== 9) {
|
|
32
|
-
// "afm should be 9 digits"
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (!/^\d+$/.test(afm)) {
|
|
37
|
-
// "This is not a number"
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (afm === '0'.repeat(9)) {
|
|
42
|
-
// "This is zero number (000000000)"
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
var sum = afm.substring(0, 8).split('').reduce(function (s, v, i) {
|
|
47
|
-
return s + (parseInt(v) << 8 - i);
|
|
48
|
-
}, 0);
|
|
49
|
-
var calc = sum % 11;
|
|
50
|
-
var d9 = parseInt(afm[8]);
|
|
51
|
-
var valid = calc % 10 === d9;
|
|
52
|
-
return valid;
|
|
53
|
-
}
|
|
54
|
-
export function validatePhoneNumber(phoneNumber) {
|
|
55
|
-
var countries = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['gr'];
|
|
56
|
-
var typeOfPhoneNumber = arguments.length > 2 ? arguments[2] : undefined;
|
|
57
|
-
var phoneUtil = gPhoneNumber.PhoneNumberUtil.getInstance();
|
|
58
|
-
|
|
59
|
-
if (!countries || countries.length === 0) {
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return countries.some(function (country) {
|
|
64
|
-
try {
|
|
65
|
-
var phone = phoneUtil.parse(phoneNumber, country.toUpperCase());
|
|
66
|
-
|
|
67
|
-
if (phoneUtil.isValidNumber(phone)) {
|
|
68
|
-
if (typeOfPhoneNumber) {
|
|
69
|
-
if (matchTypeOfPhoneNumber(phone, typeOfPhoneNumber, phoneUtil)) {
|
|
70
|
-
return true;
|
|
71
|
-
} else {
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
} else {
|
|
75
|
-
return true;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return false;
|
|
80
|
-
} catch (error) {
|
|
81
|
-
console.error(error);
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
var phoneNumberTypes = {
|
|
87
|
-
0: 'landline',
|
|
88
|
-
1: 'mobile',
|
|
89
|
-
2: 'landline_or_mobile'
|
|
90
|
-
};
|
|
91
|
-
export function matchTypeOfPhoneNumber(phone, type, phoneUtil) {
|
|
92
|
-
try {
|
|
93
|
-
var phoneNumberType = phoneUtil.getNumberType(phone);
|
|
94
|
-
var numberType = phoneNumberTypes[phoneNumberType];
|
|
95
|
-
|
|
96
|
-
if (numberType === 'landline_or_mobile' || numberType === type) {
|
|
97
|
-
return true;
|
|
98
|
-
} else {
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
} catch (error) {
|
|
102
|
-
console.error(error);
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function validateMobile(value) {
|
|
108
|
-
var phoneUtil = gPhoneNumber.PhoneNumberUtil.getInstance();
|
|
109
|
-
var origValue = value; // probably catch all the cases with a regex instead of gphonenumber
|
|
110
|
-
|
|
111
|
-
if (!value.match(/^((\+|00){0,1}\d{1,3}[- ]?)?\d{10}$/)) {
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
try {
|
|
116
|
-
var phone;
|
|
117
|
-
|
|
118
|
-
try {
|
|
119
|
-
phone = phoneUtil.parse(value);
|
|
120
|
-
} catch (err) {
|
|
121
|
-
try {
|
|
122
|
-
value = '+' + value;
|
|
123
|
-
phone = phoneUtil.parse(value);
|
|
124
|
-
} catch (err) {
|
|
125
|
-
value = '+30' + origValue;
|
|
126
|
-
phone = phoneUtil.parse(value);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return phoneUtil.isValidNumber(phone);
|
|
131
|
-
} catch (err) {
|
|
132
|
-
console.error(err);
|
|
133
|
-
return false;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
var POSTALCODE_VALIDATOR = function POSTALCODE_VALIDATOR(field) {
|
|
138
|
-
var _field$extra;
|
|
139
|
-
|
|
140
|
-
var countryCode = field === null || field === void 0 ? void 0 : (_field$extra = field.extra) === null || _field$extra === void 0 ? void 0 : _field$extra.countries;
|
|
141
|
-
return {
|
|
142
|
-
name: 'postal-code-validator',
|
|
143
|
-
message: 'form.error.postalCode',
|
|
144
|
-
test: function test(value) {
|
|
145
|
-
if (!value) {
|
|
146
|
-
return true;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return validatePostalCode(value, countryCode);
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
var MOBILE_PHONE_VALIDATOR = {
|
|
155
|
-
name: 'mobile-phone-validator',
|
|
156
|
-
message: 'form.error.mobile_phone',
|
|
157
|
-
test: function test(value) {
|
|
158
|
-
if (value) {
|
|
159
|
-
return validateMobile(value);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return true;
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
var PHONE_NUMBER_VALIDATOR = function PHONE_NUMBER_VALIDATOR(field) {
|
|
167
|
-
var _field$extra2, _field$extra3;
|
|
168
|
-
|
|
169
|
-
var countryCode = field === null || field === void 0 ? void 0 : (_field$extra2 = field.extra) === null || _field$extra2 === void 0 ? void 0 : _field$extra2.countries;
|
|
170
|
-
var typeOfPhone = field === null || field === void 0 ? void 0 : (_field$extra3 = field.extra) === null || _field$extra3 === void 0 ? void 0 : _field$extra3.phoneType;
|
|
171
|
-
return {
|
|
172
|
-
name: 'phone-number-validator',
|
|
173
|
-
message: function message() {
|
|
174
|
-
if (typeOfPhone === 'mobile') {
|
|
175
|
-
return 'form.error.mobile_phone';
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
if (typeOfPhone === 'landline') {
|
|
179
|
-
return 'form.error.landline';
|
|
180
|
-
} else {
|
|
181
|
-
return 'form.error.phone_number';
|
|
182
|
-
}
|
|
183
|
-
},
|
|
184
|
-
test: function test(value) {
|
|
185
|
-
if (!value) {
|
|
186
|
-
return true;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
return validatePhoneNumber(value, countryCode, typeOfPhone);
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
var AFM_VALIDATOR = {
|
|
195
|
-
name: 'afm-validator',
|
|
196
|
-
message: 'form.error.afm',
|
|
197
|
-
test: function test(value) {
|
|
198
|
-
if (value) {
|
|
199
|
-
return validateAFM(value);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
return true;
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
var UUID4_PATTERN = /^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i;
|
|
206
|
-
export function validateUUID4(uuid4) {
|
|
207
|
-
if (uuid4.length !== 36) {
|
|
208
|
-
// This uuid4 should be 36 characters long
|
|
209
|
-
return false;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
return UUID4_PATTERN.test(uuid4);
|
|
213
|
-
}
|
|
214
|
-
var UUID4_VALIDATOR = {
|
|
215
|
-
name: 'uuid4-validator',
|
|
216
|
-
message: 'form.error.uuid4',
|
|
217
|
-
test: function test(value) {
|
|
218
|
-
if (value) {
|
|
219
|
-
return validateUUID4(value);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
return true;
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
var FILE_MAX_SIZE = function FILE_MAX_SIZE(field) {
|
|
227
|
-
return {
|
|
228
|
-
name: 'file-max-size-validator',
|
|
229
|
-
message: 'form.error.file_size',
|
|
230
|
-
test: function test(value) {
|
|
231
|
-
if (field.extra && field.extra.maxSize && value) {
|
|
232
|
-
var _iterator = _createForOfIteratorHelper(value),
|
|
233
|
-
_step;
|
|
234
|
-
|
|
235
|
-
try {
|
|
236
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
237
|
-
var file = _step.value;
|
|
238
|
-
|
|
239
|
-
if (file.size >= field.extra.maxSize) {
|
|
240
|
-
return false;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
} catch (err) {
|
|
244
|
-
_iterator.e(err);
|
|
245
|
-
} finally {
|
|
246
|
-
_iterator.f();
|
|
247
|
-
}
|
|
248
|
-
} else if (value) {
|
|
249
|
-
var _iterator2 = _createForOfIteratorHelper(value),
|
|
250
|
-
_step2;
|
|
251
|
-
|
|
252
|
-
try {
|
|
253
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
254
|
-
var _file = _step2.value;
|
|
255
|
-
|
|
256
|
-
if (_file.size >= DEFAULT_FILE_MAX_SIZE) {
|
|
257
|
-
return false;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
} catch (err) {
|
|
261
|
-
_iterator2.e(err);
|
|
262
|
-
} finally {
|
|
263
|
-
_iterator2.f();
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
return true;
|
|
268
|
-
}
|
|
269
|
-
};
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
var ibanCountryCodesLengths = {
|
|
273
|
-
AD: 24,
|
|
274
|
-
AT: 20,
|
|
275
|
-
AZ: 28,
|
|
276
|
-
BH: 22,
|
|
277
|
-
BY: 28,
|
|
278
|
-
BE: 16,
|
|
279
|
-
BA: 20,
|
|
280
|
-
BR: 29,
|
|
281
|
-
BG: 22,
|
|
282
|
-
CR: 22,
|
|
283
|
-
HR: 21,
|
|
284
|
-
CY: 28,
|
|
285
|
-
CZ: 24,
|
|
286
|
-
DK: 18,
|
|
287
|
-
DO: 28,
|
|
288
|
-
EG: 29,
|
|
289
|
-
SV: 28,
|
|
290
|
-
EE: 20,
|
|
291
|
-
FO: 18,
|
|
292
|
-
FI: 18,
|
|
293
|
-
FR: 27,
|
|
294
|
-
GE: 22,
|
|
295
|
-
DE: 22,
|
|
296
|
-
GI: 23,
|
|
297
|
-
GR: 27,
|
|
298
|
-
GL: 18,
|
|
299
|
-
GT: 28,
|
|
300
|
-
VA: 22,
|
|
301
|
-
HU: 28,
|
|
302
|
-
IS: 26,
|
|
303
|
-
IQ: 23,
|
|
304
|
-
IE: 22,
|
|
305
|
-
IL: 23,
|
|
306
|
-
IT: 27,
|
|
307
|
-
JO: 30,
|
|
308
|
-
KZ: 20,
|
|
309
|
-
XK: 20,
|
|
310
|
-
KW: 30,
|
|
311
|
-
LV: 21,
|
|
312
|
-
LB: 28,
|
|
313
|
-
LI: 21,
|
|
314
|
-
LT: 20,
|
|
315
|
-
LU: 20,
|
|
316
|
-
MT: 31,
|
|
317
|
-
MR: 27,
|
|
318
|
-
MU: 30,
|
|
319
|
-
MD: 24,
|
|
320
|
-
MC: 27,
|
|
321
|
-
ME: 22,
|
|
322
|
-
NL: 18,
|
|
323
|
-
MK: 19,
|
|
324
|
-
NO: 15,
|
|
325
|
-
PK: 24,
|
|
326
|
-
PS: 29,
|
|
327
|
-
PL: 28,
|
|
328
|
-
PT: 25,
|
|
329
|
-
QA: 29,
|
|
330
|
-
RO: 24,
|
|
331
|
-
LC: 32,
|
|
332
|
-
SM: 27,
|
|
333
|
-
ST: 25,
|
|
334
|
-
SA: 24,
|
|
335
|
-
RS: 22,
|
|
336
|
-
SC: 31,
|
|
337
|
-
SK: 24,
|
|
338
|
-
SI: 19,
|
|
339
|
-
ES: 24,
|
|
340
|
-
SE: 24,
|
|
341
|
-
CH: 21,
|
|
342
|
-
TL: 23,
|
|
343
|
-
TN: 24,
|
|
344
|
-
TR: 26,
|
|
345
|
-
UA: 29,
|
|
346
|
-
AE: 23,
|
|
347
|
-
GB: 22,
|
|
348
|
-
VG: 24
|
|
349
|
-
};
|
|
350
|
-
export function validateIban(value, countryCode) {
|
|
351
|
-
value = value.replace(/\s/g, '').replace(/-/g, '');
|
|
352
|
-
|
|
353
|
-
if (value.match(/^[0-9]*$/i)) {
|
|
354
|
-
// this is for greek iban without the country code
|
|
355
|
-
if (value.length !== 25) {
|
|
356
|
-
return false;
|
|
357
|
-
}
|
|
358
|
-
} else {
|
|
359
|
-
value = value.toUpperCase();
|
|
360
|
-
|
|
361
|
-
if (countryCode) {
|
|
362
|
-
if (!value.startsWith(countryCode.toUpperCase())) {
|
|
363
|
-
return false;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
if (value.length === ibanCountryCodesLengths[countryCode.toUpperCase()]) {
|
|
367
|
-
return true;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
if (value.length !== 27) {
|
|
372
|
-
// this is for greek iban
|
|
373
|
-
return false;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
return true;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
var IBAN_VALIDATOR = function IBAN_VALIDATOR(field) {
|
|
381
|
-
var _field$extra4;
|
|
382
|
-
|
|
383
|
-
var countryCode = field === null || field === void 0 ? void 0 : (_field$extra4 = field.extra) === null || _field$extra4 === void 0 ? void 0 : _field$extra4.country;
|
|
384
|
-
return {
|
|
385
|
-
name: 'iban-validator',
|
|
386
|
-
message: 'form.error.iban',
|
|
387
|
-
test: function test(value) {
|
|
388
|
-
if (!value) {
|
|
389
|
-
return true;
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
return validateIban(value, countryCode);
|
|
393
|
-
}
|
|
394
|
-
};
|
|
395
|
-
};
|
|
396
|
-
|
|
397
|
-
var VALID_DATE_FORMATS = ['DD/MM/YYYY'];
|
|
398
|
-
var DATE_CACHE = {};
|
|
399
|
-
|
|
400
|
-
var getDate = function getDate(v) {
|
|
401
|
-
return DATE_CACHE[v] ? DATE_CACHE[v] : dayjs(v, VALID_DATE_FORMATS, true);
|
|
402
|
-
};
|
|
403
|
-
|
|
404
|
-
function getYupField(field, yupTypeMap) {
|
|
405
|
-
var yupField = yupTypeMap[field.type] || yupTypeMap.string;
|
|
406
|
-
return yupField(field);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
function computeShape(fields, yupTypeMap, validatorRegistry) {
|
|
410
|
-
var fieldSchemas = {};
|
|
411
|
-
var objectFields = {};
|
|
412
|
-
fields.forEach(function (field) {
|
|
413
|
-
if (field.key.includes('.')) {
|
|
414
|
-
var _field$key$split = field.key.split(/\.(.+)/),
|
|
415
|
-
_field$key$split2 = _slicedToArray(_field$key$split, 2),
|
|
416
|
-
objectKey = _field$key$split2[0],
|
|
417
|
-
fieldKey = _field$key$split2[1];
|
|
418
|
-
|
|
419
|
-
if (!objectFields[objectKey]) {
|
|
420
|
-
objectFields[objectKey] = [];
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
objectFields[objectKey].push(_extends({}, field, {
|
|
424
|
-
key: fieldKey
|
|
425
|
-
}));
|
|
426
|
-
return;
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
var yupField = getYupField(field, yupTypeMap);
|
|
430
|
-
|
|
431
|
-
if (field.condition) {
|
|
432
|
-
for (var key in field.condition) {
|
|
433
|
-
var then = void 0,
|
|
434
|
-
otherwise = void 0;
|
|
435
|
-
|
|
436
|
-
if (field.condition[key].then) {
|
|
437
|
-
var _field$condition$key$, _field$condition$key$2;
|
|
438
|
-
|
|
439
|
-
if (((_field$condition$key$ = field.condition[key].then) === null || _field$condition$key$ === void 0 ? void 0 : _field$condition$key$.required) === false) {
|
|
440
|
-
then = yupField;
|
|
441
|
-
} else if (((_field$condition$key$2 = field.condition[key].then) === null || _field$condition$key$2 === void 0 ? void 0 : _field$condition$key$2.required) === true) {
|
|
442
|
-
then = yupField.required('form.error.required');
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
if (field.condition[key]["else"]) {
|
|
447
|
-
var _field$condition$key$3, _field$condition$key$4;
|
|
448
|
-
|
|
449
|
-
if (((_field$condition$key$3 = field.condition[key]["else"]) === null || _field$condition$key$3 === void 0 ? void 0 : _field$condition$key$3.required) === false) {
|
|
450
|
-
otherwise = yupField;
|
|
451
|
-
} else if (((_field$condition$key$4 = field.condition[key]["else"]) === null || _field$condition$key$4 === void 0 ? void 0 : _field$condition$key$4.required) === true) {
|
|
452
|
-
otherwise = yupField.required('form.error.required');
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
if (then || otherwise) {
|
|
457
|
-
yupField = yupField.when(key, {
|
|
458
|
-
is: field.condition[key].is,
|
|
459
|
-
then: then,
|
|
460
|
-
otherwise: otherwise
|
|
461
|
-
});
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
} else if (field.required) {
|
|
465
|
-
yupField = yupField.required('form.error.required');
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
if (validatorRegistry && field.type && validatorRegistry[field.type]) {
|
|
469
|
-
validatorRegistry[field.type].forEach(function (validator) {
|
|
470
|
-
yupField = yupField.test(validator);
|
|
471
|
-
});
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
if (field.validators) {
|
|
475
|
-
field.validators.forEach(function (validator) {
|
|
476
|
-
yupField = yupField.test(validator);
|
|
477
|
-
});
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
fieldSchemas[field.key] = yupField;
|
|
481
|
-
});
|
|
482
|
-
|
|
483
|
-
for (var objectKey in objectFields) {
|
|
484
|
-
fieldSchemas[objectKey] = getYupObjectShape(objectFields[objectKey], yupTypeMap, validatorRegistry);
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
return fieldSchemas;
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
function getYupObjectShape( // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
491
|
-
fields, yupTypeMap, validatorRegistry) {
|
|
492
|
-
if (!fields.current) {
|
|
493
|
-
var fieldSchemas = computeShape(fields, yupTypeMap, validatorRegistry);
|
|
494
|
-
return yup.object().shape(fieldSchemas);
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
return yup.lazy(function () {
|
|
498
|
-
var fieldSchemas = computeShape(Object.values(fields.current), yupTypeMap, validatorRegistry);
|
|
499
|
-
return yup.object().shape(fieldSchemas);
|
|
500
|
-
});
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
var getYUPTypeMap = function getYUPTypeMap() {
|
|
504
|
-
var yupTypeMap = {
|
|
505
|
-
file: function file(field) {
|
|
506
|
-
return yup.mixed().transform(function (value) {
|
|
507
|
-
if (!value.length) {
|
|
508
|
-
return null;
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
return value;
|
|
512
|
-
}).nullable().test(FILE_MAX_SIZE(field));
|
|
513
|
-
},
|
|
514
|
-
string: yup.string,
|
|
515
|
-
text: yup.string,
|
|
516
|
-
"boolean": yup["boolean"],
|
|
517
|
-
"int": function int() {
|
|
518
|
-
return yup.number().typeError('form.error.number').positive('form.error.positive_number');
|
|
519
|
-
},
|
|
520
|
-
email: function email() {
|
|
521
|
-
return yup.string().email('form.error.email');
|
|
522
|
-
},
|
|
523
|
-
afm: function afm() {
|
|
524
|
-
return yup.string().test(AFM_VALIDATOR);
|
|
525
|
-
},
|
|
526
|
-
uuid4: function uuid4() {
|
|
527
|
-
return yup.string().test(UUID4_VALIDATOR);
|
|
528
|
-
},
|
|
529
|
-
iban: function iban(field) {
|
|
530
|
-
return yup.string().test(IBAN_VALIDATOR(field));
|
|
531
|
-
},
|
|
532
|
-
postal_code: function postal_code(field) {
|
|
533
|
-
return yup.string().test(POSTALCODE_VALIDATOR(field));
|
|
534
|
-
},
|
|
535
|
-
mobile_phone: function mobile_phone() {
|
|
536
|
-
return yup.string().test(MOBILE_PHONE_VALIDATOR);
|
|
537
|
-
},
|
|
538
|
-
phone_number: function phone_number(field) {
|
|
539
|
-
return yup.string().test(PHONE_NUMBER_VALIDATOR(field));
|
|
540
|
-
},
|
|
541
|
-
'choice:multiple': function choiceMultiple() {
|
|
542
|
-
return yup.array().of(yup.string()).nullable();
|
|
543
|
-
},
|
|
544
|
-
'choice:single': function choiceSingle() {
|
|
545
|
-
return yup.string().nullable();
|
|
546
|
-
},
|
|
547
|
-
date: function date(field) {
|
|
548
|
-
var simpleDate = yup.string().nullable(true).test('date', 'form.error.date.invalid', function (value) {
|
|
549
|
-
if (!value) return true;
|
|
550
|
-
value = getDate(value);
|
|
551
|
-
return value.isValid();
|
|
552
|
-
});
|
|
553
|
-
var params = field.extra || {};
|
|
554
|
-
|
|
555
|
-
if (params.max) {
|
|
556
|
-
var maxDate;
|
|
557
|
-
|
|
558
|
-
if (params.max === 'now') {
|
|
559
|
-
var today = new Date();
|
|
560
|
-
maxDate = new Date(today);
|
|
561
|
-
} else {
|
|
562
|
-
maxDate = getDate(params.max).toDate();
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
var maxNextDate = new Date(maxDate);
|
|
566
|
-
maxNextDate.setDate(maxDate.getDate() + 1);
|
|
567
|
-
simpleDate = simpleDate.test({
|
|
568
|
-
name: 'earlier-than',
|
|
569
|
-
message: {
|
|
570
|
-
key: 'form.error.date.earlier_than',
|
|
571
|
-
context: {
|
|
572
|
-
maxDate: maxNextDate.toLocaleDateString()
|
|
573
|
-
}
|
|
574
|
-
},
|
|
575
|
-
test: function test(value) {
|
|
576
|
-
if (!value) return true;
|
|
577
|
-
value = getDate(value);
|
|
578
|
-
var isValid = +value.toDate() < +maxDate;
|
|
579
|
-
return isValid;
|
|
580
|
-
}
|
|
581
|
-
});
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
if (params.min) {
|
|
585
|
-
var minDate;
|
|
586
|
-
|
|
587
|
-
if (params.min === 'now') {
|
|
588
|
-
var _today = new Date();
|
|
589
|
-
|
|
590
|
-
minDate = new Date(_today);
|
|
591
|
-
} else {
|
|
592
|
-
minDate = getDate(params.min).toDate();
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
var minPreviousDate = new Date(minDate);
|
|
596
|
-
minPreviousDate.setDate(minDate.getDate() - 1);
|
|
597
|
-
simpleDate = simpleDate.test({
|
|
598
|
-
name: 'later-than',
|
|
599
|
-
message: {
|
|
600
|
-
key: 'form.error.date.later_than',
|
|
601
|
-
context: {
|
|
602
|
-
minDate: minPreviousDate.toLocaleDateString()
|
|
603
|
-
}
|
|
604
|
-
},
|
|
605
|
-
test: function test(value) {
|
|
606
|
-
if (!value) return true;
|
|
607
|
-
value = getDate(value);
|
|
608
|
-
var isValid = +value.toDate() > +minDate;
|
|
609
|
-
return isValid;
|
|
610
|
-
}
|
|
611
|
-
});
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
return simpleDate;
|
|
615
|
-
}
|
|
616
|
-
};
|
|
617
|
-
return yupTypeMap;
|
|
618
|
-
};
|
|
619
|
-
|
|
620
|
-
// Create a yup validation schema from given fields input
|
|
621
|
-
export function useValidationSchema(fields, validatorRegistry) {
|
|
622
|
-
return useMemo(function () {
|
|
623
|
-
var yupTypeMap = getYUPTypeMap();
|
|
624
|
-
return getYupObjectShape(fields, yupTypeMap, validatorRegistry);
|
|
625
|
-
}, []);
|
|
626
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { UseFormMethods } from 'react-hook-form';
|
|
3
|
-
import { CalculatedField } from '@digigov/form/Field/';
|
|
4
|
-
import { FieldCondition, FieldError, FormData } from '@digigov/form/';
|
|
5
|
-
export interface ChildFieldMemoProps extends ConditionalFieldProps {
|
|
6
|
-
dependencies: FormData;
|
|
7
|
-
}
|
|
8
|
-
export interface FieldWithCondition extends Omit<CalculatedField, 'condition'> {
|
|
9
|
-
condition: Record<string, FieldCondition>;
|
|
10
|
-
}
|
|
11
|
-
export interface ConditionalFieldProps {
|
|
12
|
-
field: FieldWithCondition;
|
|
13
|
-
control: UseFormMethods['control'];
|
|
14
|
-
register: UseFormMethods['register'];
|
|
15
|
-
error?: FieldError;
|
|
16
|
-
}
|
|
17
|
-
export declare const ConditionalField: React.FC<ConditionalFieldProps>;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import * as yup from 'yup';
|
|
2
|
-
import { FieldSpec } from '@digigov/form';
|
|
3
|
-
import { MutableRefObject } from 'react';
|
|
4
|
-
export declare type ValidatorSchema = yup.BaseTestOptions;
|
|
5
|
-
export declare function validatePostalCode(number: string, countries: Array<string>): boolean;
|
|
6
|
-
export declare function validateAFM(afm: string): boolean;
|
|
7
|
-
export declare type PhoneNumberType = 'landline' | 'mobile' | null;
|
|
8
|
-
export declare function validatePhoneNumber(phoneNumber: string, countries: string[] | undefined, typeOfPhoneNumber: PhoneNumberType): boolean;
|
|
9
|
-
export declare function matchTypeOfPhoneNumber(phone: any, type: string, phoneUtil: any): boolean;
|
|
10
|
-
export declare function validateUUID4(uuid4: string): boolean;
|
|
11
|
-
export declare function validateIban(value: string, countryCode: string): boolean;
|
|
12
|
-
export interface MutableRefObjectProps {
|
|
13
|
-
}
|
|
14
|
-
export declare function useValidationSchema(fields: FieldSpec[] | MutableRefObject<MutableRefObjectProps>, validatorRegistry?: Record<string, ValidatorSchema>): Record<string, unknown> | void;
|