@digigov/form 2.0.0-49de50c4 → 2.0.0-555d1027
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/Field/FieldBase/index.js +3 -4
- package/Field/FieldBase.js.map +2 -2
- package/Field/FieldBaseContainer/index.js +18 -2
- package/Field/FieldBaseContainer.js.map +2 -2
- package/Field/FieldConditional/index.js +1 -1
- package/Field/FieldConditional.js.map +1 -1
- package/Field/index.js +2 -1
- package/Field/index.js.map +2 -2
- package/Field/types.d.ts +2 -2
- package/Field/utils/index.js +4 -3
- package/Field/utils/index.js.map +2 -2
- package/FieldArray/FormDialog/index.js +5 -8
- package/FieldArray/FormDialog.d.ts +4 -4
- package/FieldArray/FormDialog.js.map +2 -2
- package/FieldArray/__stories__/Default.d.ts +1 -1
- package/FieldArray/__stories__/WithExactLength.d.ts +1 -1
- package/FieldArray/__stories__/WithModal.d.ts +1 -1
- package/FieldArray/index.d.ts +1 -1
- package/FieldArray/index.js +75 -87
- package/FieldArray/index.js.map +3 -3
- package/FormBuilder/FormBuilder.stories.d.ts +2 -0
- package/FormBuilder/__stories__/AutoErrorGrouping.d.ts +1 -1
- package/FormBuilder/__stories__/Default.d.ts +1 -1
- package/FormBuilder/__stories__/ErrorGrouping.d.ts +1 -1
- package/FormBuilder/index.d.ts +1 -1
- package/FormBuilder/index.js +3 -7
- package/FormBuilder/index.js.map +2 -2
- package/FormContext/index.js +6 -2
- package/FormContext.d.ts +1 -0
- package/FormContext.js.map +2 -2
- package/MultiplicityField/MultiplicityField.stories.d.ts +2 -0
- package/MultiplicityField/__stories__/Default.d.ts +1 -1
- package/MultiplicityField/__stories__/PreviewDisplay.d.ts +1 -1
- package/MultiplicityField/__stories__/WithExactLength.d.ts +1 -1
- package/MultiplicityField/__stories__/WithMaxLength.d.ts +1 -1
- package/MultiplicityField/__stories__/WithMinAndMaxLength.d.ts +1 -1
- package/MultiplicityField/__stories__/WithMinLength.d.ts +1 -1
- package/MultiplicityField/add-objects/index.js +1 -1
- package/MultiplicityField/add-objects.js.map +2 -2
- package/MultiplicityField/index.js +4 -2
- package/MultiplicityField/index.js.map +2 -2
- package/MultiplicityField/types.d.ts +1 -0
- package/Questions/Questions.stories.d.ts +2 -0
- package/Questions/__stories__/Default.d.ts +1 -1
- package/cjs/Field/FieldBase/index.js +3 -4
- package/cjs/Field/FieldBase.js.map +2 -2
- package/cjs/Field/FieldBaseContainer/index.js +17 -1
- package/cjs/Field/FieldBaseContainer.js.map +3 -3
- package/cjs/Field/FieldConditional/index.js +1 -1
- package/cjs/Field/FieldConditional.js.map +1 -1
- package/cjs/Field/index.js +2 -1
- package/cjs/Field/index.js.map +2 -2
- package/cjs/Field/types.js.map +1 -1
- package/cjs/Field/utils/index.js +4 -3
- package/cjs/Field/utils/index.js.map +2 -2
- package/cjs/FieldArray/FormDialog/index.js +5 -8
- package/cjs/FieldArray/FormDialog.js.map +2 -2
- package/cjs/FieldArray/index.js +74 -83
- package/cjs/FieldArray/index.js.map +3 -3
- package/cjs/FormBuilder/index.js +3 -7
- package/cjs/FormBuilder/index.js.map +2 -2
- package/cjs/FormContext/index.js +7 -2
- package/cjs/FormContext.js.map +2 -2
- package/cjs/MultiplicityField/add-objects/index.js +1 -1
- package/cjs/MultiplicityField/add-objects.js.map +2 -2
- package/cjs/MultiplicityField/index.js +4 -2
- package/cjs/MultiplicityField/index.js.map +2 -2
- package/cjs/MultiplicityField/types.js.map +1 -1
- package/cjs/inputs/Checkboxes/index.js +2 -1
- package/cjs/inputs/Checkboxes/index.js.map +2 -2
- package/cjs/inputs/DateInput/index.js +27 -12
- package/cjs/inputs/DateInput/index.js.map +2 -2
- package/cjs/inputs/DateTimeInput/index.js +55 -34
- package/cjs/inputs/DateTimeInput/index.js.map +2 -2
- package/cjs/inputs/FileInput/index.js +45 -26
- package/cjs/inputs/FileInput/index.js.map +2 -2
- package/cjs/inputs/ImageInput/__stories__/logo.d/index.js +1 -0
- package/cjs/inputs/ImageInput/__stories__/logo.d.js.map +7 -0
- package/cjs/inputs/ImageInput/index.js +41 -10
- package/cjs/inputs/ImageInput/index.js.map +2 -2
- package/cjs/inputs/Input/index.js +1 -0
- package/cjs/inputs/Input/index.js.map +2 -2
- package/cjs/lazy/index.js +1 -1
- package/cjs/lazy.js.map +2 -2
- package/cjs/registry/index.js +4 -6
- package/cjs/registry.js.map +2 -2
- package/cjs/validators/index.js +8 -10
- package/cjs/validators/index.js.map +2 -2
- package/cjs/validators/utils/date/index.js +21 -3
- package/cjs/validators/utils/date.js.map +2 -2
- package/cjs/validators/utils/datetime/index.js +113 -24
- package/cjs/validators/utils/datetime.js.map +2 -2
- package/index.js +1 -1
- package/inputs/AutoCompleteInput/AutoComplete.stories.d.ts +2 -0
- package/inputs/AutoCompleteInput/__stories__/Default.d.ts +1 -1
- package/inputs/AutoCompleteInput/__stories__/Multiple.d.ts +1 -1
- package/inputs/Checkboxes/Checkboxes.stories.d.ts +2 -0
- package/inputs/Checkboxes/__stories__/Conditional.d.ts +1 -1
- package/inputs/Checkboxes/__stories__/Default.d.ts +1 -1
- package/inputs/Checkboxes/__stories__/WithDivider.d.ts +1 -1
- package/inputs/Checkboxes/index.js +2 -1
- package/inputs/Checkboxes/index.js.map +2 -2
- package/inputs/DateInput/DateInput.stories.d.ts +6 -0
- package/inputs/DateInput/__stories__/Default.d.ts +1 -1
- package/inputs/DateInput/__stories__/WithDefaultValue.d.ts +3 -0
- package/inputs/DateInput/__stories__/WithInitialValue.d.ts +3 -0
- package/inputs/DateInput/__stories__/WithWrongDefaultValue.d.ts +3 -0
- package/inputs/DateInput/__stories__/WithWrongInitialValue.d.ts +3 -0
- package/inputs/DateInput/index.js +28 -13
- package/inputs/DateInput/index.js.map +2 -2
- package/inputs/DateTimeInput/DateTimeInput.stories.d.ts +10 -3
- package/inputs/DateTimeInput/__stories__/Default.d.ts +1 -1
- package/inputs/DateTimeInput/__stories__/WithDefaultValue.d.ts +3 -0
- package/inputs/DateTimeInput/__stories__/WithInitialValue.d.ts +3 -0
- package/inputs/DateTimeInput/__stories__/WithWrongDefaultValue.d.ts +3 -0
- package/inputs/DateTimeInput/__stories__/WithWrongInitialValue.d.ts +3 -0
- package/inputs/DateTimeInput/index.js +56 -35
- package/inputs/DateTimeInput/index.js.map +2 -2
- package/inputs/FileInput/FileInput.stories.d.ts +2 -0
- package/inputs/FileInput/__stories__/Default.d.ts +1 -1
- package/inputs/FileInput/index.d.ts +5 -1
- package/inputs/FileInput/index.js +46 -27
- package/inputs/FileInput/index.js.map +2 -2
- package/inputs/ImageInput/ImageInput.stories.d.ts +4 -1
- package/inputs/ImageInput/__stories__/Default.d.ts +1 -1
- package/inputs/ImageInput/__stories__/MaxSize.d.ts +1 -1
- package/inputs/ImageInput/__stories__/WithInitialValues.d.ts +3 -0
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension.d.ts +1 -1
- package/inputs/ImageInput/__stories__/logo.d/index.js +1 -0
- package/inputs/{Input/inputsInputScenarios → ImageInput/__stories__/logo.d}/package.json +1 -1
- package/inputs/ImageInput/__stories__/logo.d.js.map +7 -0
- package/inputs/ImageInput/index.d.ts +9 -1
- package/inputs/ImageInput/index.js +42 -11
- package/inputs/ImageInput/index.js.map +2 -2
- package/inputs/Input/Input.stories.d.ts +3 -0
- package/inputs/Input/__stories__/AFM.d.ts +1 -1
- package/inputs/Input/__stories__/Boolean.d.ts +1 -1
- package/inputs/Input/__stories__/Email.d.ts +3 -0
- package/inputs/Input/__stories__/IBAN.d.ts +1 -1
- package/inputs/Input/__stories__/Integer.d.ts +1 -1
- package/inputs/Input/__stories__/LandlineNumber.d.ts +1 -1
- package/inputs/Input/__stories__/MobilePhone.d.ts +1 -1
- package/inputs/Input/__stories__/PhoneNumber.d.ts +1 -1
- package/inputs/Input/__stories__/PostalCode.d.ts +1 -1
- package/inputs/Input/__stories__/String.d.ts +1 -1
- package/inputs/Input/__stories__/StringWithTrimValidation.d.ts +1 -1
- package/inputs/Input/__stories__/TextWithLimit.d.ts +1 -1
- package/inputs/Input/index.js +1 -0
- package/inputs/Input/index.js.map +2 -2
- package/inputs/Label/Label.stories.d.ts +2 -0
- package/inputs/Label/__stories__/Default.d.ts +1 -1
- package/inputs/OtpInput/OtpInput.stories.d.ts +2 -0
- package/inputs/OtpInput/__stories__/Default.d.ts +1 -1
- package/inputs/Radio/Radio.stories.d.ts +2 -0
- package/inputs/Radio/__stories__/Conditional.d.ts +1 -1
- package/inputs/Radio/__stories__/Default.d.ts +1 -1
- package/inputs/Radio/__stories__/WithDivider.d.ts +1 -1
- package/inputs/Select/Select.stories.d.ts +2 -0
- package/inputs/Select/__stories__/Default.d.ts +1 -1
- package/lazy/index.js +1 -1
- package/package.json +8 -8
- package/registry/index.js +4 -6
- package/src/Field/FieldBase.tsx +14 -18
- package/src/Field/FieldBaseContainer.tsx +13 -5
- package/src/Field/FieldConditional.tsx +1 -1
- package/src/Field/index.tsx +2 -1
- package/src/Field/types.tsx +2 -2
- package/src/Field/utils/index.ts +2 -1
- package/src/FieldArray/FormDialog.tsx +7 -13
- package/src/FieldArray/__stories__/Default.tsx +1 -1
- package/src/FieldArray/__stories__/WithExactLength.tsx +1 -1
- package/src/FieldArray/__stories__/WithModal.tsx +1 -1
- package/src/FieldArray/index.tsx +83 -102
- package/src/FormBuilder/FormBuilder.stories.js +3 -0
- package/src/FormBuilder/__stories__/AutoErrorGrouping.tsx +1 -1
- package/src/FormBuilder/__stories__/Default.tsx +1 -1
- package/src/FormBuilder/__stories__/ErrorGrouping.tsx +1 -1
- package/src/FormBuilder/index.tsx +3 -7
- package/src/FormBuilder/scenarios.test.tsx +1 -1
- package/src/FormContext.tsx +5 -1
- package/src/MultiplicityField/MultiplicityField.stories.js +3 -0
- package/src/MultiplicityField/__stories__/Default.tsx +1 -1
- package/src/MultiplicityField/__stories__/PreviewDisplay.tsx +1 -1
- package/src/MultiplicityField/__stories__/WithExactLength.tsx +1 -1
- package/src/MultiplicityField/__stories__/WithMaxLength.tsx +1 -1
- package/src/MultiplicityField/__stories__/WithMinAndMaxLength.tsx +1 -1
- package/src/MultiplicityField/__stories__/WithMinLength.tsx +1 -1
- package/src/MultiplicityField/add-objects.tsx +1 -1
- package/src/MultiplicityField/index.tsx +3 -1
- package/src/MultiplicityField/types.ts +1 -0
- package/src/Questions/Questions.stories.js +3 -0
- package/src/Questions/__stories__/Default.tsx +1 -1
- package/src/inputs/AutoCompleteInput/AutoComplete.stories.js +3 -0
- package/src/inputs/AutoCompleteInput/__stories__/Default.tsx +1 -1
- package/src/inputs/AutoCompleteInput/__stories__/Multiple.tsx +1 -1
- package/src/inputs/Checkboxes/Checkboxes.stories.js +3 -0
- package/src/inputs/Checkboxes/__stories__/Conditional.tsx +1 -1
- package/src/inputs/Checkboxes/__stories__/Default.tsx +1 -1
- package/src/inputs/Checkboxes/__stories__/WithDivider.tsx +1 -1
- package/src/inputs/Checkboxes/index.tsx +4 -5
- package/src/inputs/DateInput/DateInput.stories.js +7 -0
- package/src/inputs/DateInput/__stories__/Default.tsx +1 -1
- package/src/inputs/DateInput/__stories__/WithDefaultValue.tsx +26 -0
- package/src/inputs/DateInput/__stories__/WithInitialValue.tsx +28 -0
- package/src/inputs/DateInput/__stories__/WithWrongDefaultValue.tsx +26 -0
- package/src/inputs/DateInput/__stories__/WithWrongInitialValue.tsx +28 -0
- package/src/inputs/DateInput/index.test.tsx +16 -0
- package/src/inputs/DateInput/index.tsx +31 -13
- package/src/inputs/DateTimeInput/DateTimeInput.stories.js +12 -6
- package/src/inputs/DateTimeInput/__stories__/Default.tsx +1 -1
- package/src/inputs/DateTimeInput/__stories__/WithDefaultValue.tsx +26 -0
- package/src/inputs/DateTimeInput/__stories__/WithInitialValue.tsx +28 -0
- package/src/inputs/DateTimeInput/__stories__/WithWrongDefaultValue.tsx +26 -0
- package/src/inputs/DateTimeInput/__stories__/WithWrongInitialValue.tsx +28 -0
- package/src/inputs/DateTimeInput/index.test.tsx +16 -0
- package/src/inputs/DateTimeInput/index.tsx +59 -35
- package/src/inputs/FileInput/FileInput.stories.js +3 -0
- package/src/inputs/FileInput/__stories__/Default.tsx +1 -1
- package/src/inputs/FileInput/index.tsx +72 -39
- package/src/inputs/ImageInput/ImageInput.stories.js +5 -1
- package/src/inputs/ImageInput/__stories__/Default.tsx +1 -1
- package/src/inputs/ImageInput/__stories__/MaxSize.tsx +3 -2
- package/src/inputs/ImageInput/__stories__/WithInitialValues.tsx +45 -0
- package/src/inputs/ImageInput/__stories__/WithInvalidImageDimension.tsx +1 -1
- package/src/inputs/ImageInput/__stories__/logo.d.ts +4 -0
- package/src/inputs/ImageInput/__stories__/logo.png +0 -0
- package/src/inputs/ImageInput/index.test.tsx +4 -0
- package/src/inputs/ImageInput/index.tsx +100 -48
- package/src/inputs/Input/Input.stories.js +4 -0
- package/src/inputs/Input/__stories__/AFM.tsx +1 -1
- package/src/inputs/Input/__stories__/Boolean.tsx +1 -1
- package/src/inputs/Input/__stories__/Email.tsx +23 -0
- package/src/inputs/Input/__stories__/IBAN.tsx +1 -1
- package/src/inputs/Input/__stories__/Integer.tsx +1 -1
- package/src/inputs/Input/__stories__/LandlineNumber.tsx +1 -1
- package/src/inputs/Input/__stories__/MobilePhone.tsx +1 -1
- package/src/inputs/Input/__stories__/PhoneNumber.tsx +1 -1
- package/src/inputs/Input/__stories__/PostalCode.tsx +1 -1
- package/src/inputs/Input/__stories__/String.tsx +1 -1
- package/src/inputs/Input/__stories__/StringWithTrimValidation.tsx +1 -1
- package/src/inputs/Input/__stories__/TextWithLimit.tsx +1 -1
- package/src/inputs/Input/index.test.tsx +8 -0
- package/src/inputs/Input/index.tsx +1 -0
- package/src/inputs/Label/Label.stories.js +3 -0
- package/src/inputs/Label/__stories__/Default.tsx +1 -1
- package/src/inputs/OtpInput/OtpInput.stories.js +3 -0
- package/src/inputs/OtpInput/__stories__/Default.tsx +1 -1
- package/src/inputs/Radio/Radio.stories.js +3 -0
- package/src/inputs/Radio/__stories__/Conditional.tsx +1 -1
- package/src/inputs/Radio/__stories__/Default.tsx +1 -1
- package/src/inputs/Radio/__stories__/WithDivider.tsx +1 -1
- package/src/inputs/Select/Select.stories.js +3 -0
- package/src/inputs/Select/__stories__/Default.tsx +1 -1
- package/src/lazy.js +1 -1
- package/src/registry.js +4 -6
- package/src/validators/index.ts +13 -13
- package/src/validators/utils/date.ts +23 -4
- package/src/validators/utils/datetime.ts +116 -29
- package/validators/index.js +8 -10
- package/validators/index.js.map +2 -2
- package/validators/utils/date/index.js +21 -3
- package/validators/utils/date.d.ts +1 -1
- package/validators/utils/date.js.map +2 -2
- package/validators/utils/datetime/index.js +113 -24
- package/validators/utils/datetime.d.ts +1 -1
- package/validators/utils/datetime.js.map +2 -2
- package/cjs/inputs/Input/inputsInputScenarios/index.js +0 -439
- package/cjs/inputs/Input/inputsInputScenarios.js.map +0 -7
- package/inputs/Input/inputsInputScenarios/index.js +0 -406
- package/inputs/Input/inputsInputScenarios.d.ts +0 -57
- package/inputs/Input/inputsInputScenarios.js.map +0 -7
- package/src/inputs/Input/inputsInputScenarios.ts +0 -404
|
@@ -2,7 +2,9 @@ import React from 'react';
|
|
|
2
2
|
import { test, expect } from '@playwright/experimental-ct-react';
|
|
3
3
|
import TestVariant from '@digigov/ui/utils/TestVariant'
|
|
4
4
|
import { AFM } from '@digigov/form/inputs/Input/__stories__/AFM';
|
|
5
|
+
import { AMKA } from '@digigov/form/inputs/Input/__stories__/AMKA';
|
|
5
6
|
import { Boolean } from '@digigov/form/inputs/Input/__stories__/Boolean';
|
|
7
|
+
import { Email } from '@digigov/form/inputs/Input/__stories__/Email';
|
|
6
8
|
import { IBAN } from '@digigov/form/inputs/Input/__stories__/IBAN';
|
|
7
9
|
import { Integer } from '@digigov/form/inputs/Input/__stories__/Integer';
|
|
8
10
|
import { LandlineNumber } from '@digigov/form/inputs/Input/__stories__/LandlineNumber';
|
|
@@ -20,9 +22,15 @@ test('renders the All Input variants', async ({ mount, page }) => {
|
|
|
20
22
|
<TestVariant title="AFM">
|
|
21
23
|
<AFM />
|
|
22
24
|
</TestVariant>
|
|
25
|
+
<TestVariant title="AMKA">
|
|
26
|
+
<AMKA />
|
|
27
|
+
</TestVariant>
|
|
23
28
|
<TestVariant title="Boolean">
|
|
24
29
|
<Boolean />
|
|
25
30
|
</TestVariant>
|
|
31
|
+
<TestVariant title="Email">
|
|
32
|
+
<Email />
|
|
33
|
+
</TestVariant>
|
|
26
34
|
<TestVariant title="IBAN">
|
|
27
35
|
<IBAN />
|
|
28
36
|
</TestVariant>
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import Label from '@digigov/form/inputs/Label';
|
|
2
|
+
import doc from './doc.mdx?raw';
|
|
2
3
|
export default {
|
|
3
4
|
title: 'Digigov Form/inputs/Label',
|
|
4
5
|
component: Label,
|
|
6
|
+
tags: ['autodocs'],
|
|
7
|
+
markdown: doc,
|
|
5
8
|
displayName: 'Label',
|
|
6
9
|
};
|
|
7
10
|
export { Default } from '@digigov/form/inputs/Label/__stories__/Default';
|
|
@@ -4,7 +4,7 @@ import Field from '@digigov/form/Field';
|
|
|
4
4
|
import Label from '@digigov/form/inputs/Label';
|
|
5
5
|
import { Button } from '@digigov/ui/form/Button';
|
|
6
6
|
|
|
7
|
-
export const Default = () => (
|
|
7
|
+
export const Default = (_: any) => (
|
|
8
8
|
<FormBuilder
|
|
9
9
|
onSubmit={(data) => {
|
|
10
10
|
console.log(data);
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import OtpInput from '@digigov/form/inputs/OtpInput';
|
|
2
|
+
import doc from './doc.mdx?raw';
|
|
2
3
|
export default {
|
|
3
4
|
title: 'Digigov Form/inputs/OtpInput',
|
|
4
5
|
component: OtpInput,
|
|
6
|
+
tags: ['autodocs'],
|
|
7
|
+
markdown: doc,
|
|
5
8
|
displayName: 'OtpInput',
|
|
6
9
|
};
|
|
7
10
|
export { Default } from '@digigov/form/inputs/OtpInput/__stories__/Default';
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import Radio from '@digigov/form/inputs/Radio';
|
|
2
|
+
import doc from './doc.mdx?raw';
|
|
2
3
|
export default {
|
|
3
4
|
title: 'Digigov Form/inputs/Radio',
|
|
4
5
|
component: Radio,
|
|
6
|
+
tags: ['autodocs'],
|
|
7
|
+
markdown: doc,
|
|
5
8
|
displayName: 'Radio',
|
|
6
9
|
};
|
|
7
10
|
export { Default } from '@digigov/form/inputs/Radio/__stories__/Default';
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import FormBuilder, { Field } from '@digigov/form';
|
|
3
3
|
import { Button } from '@digigov/ui/form/Button';
|
|
4
4
|
|
|
5
|
-
export const WithDivider = () => (
|
|
5
|
+
export const WithDivider = (_: any) => (
|
|
6
6
|
<FormBuilder
|
|
7
7
|
onSubmit={(data) => {
|
|
8
8
|
console.log(data);
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import Select from '@digigov/form/inputs/Select';
|
|
2
|
+
import doc from './doc.mdx?raw';
|
|
2
3
|
export default {
|
|
3
4
|
title: 'Digigov Form/inputs/Select',
|
|
4
5
|
component: Select,
|
|
6
|
+
tags: ['autodocs'],
|
|
7
|
+
markdown: doc,
|
|
5
8
|
displayName: 'Select',
|
|
6
9
|
};
|
|
7
10
|
export { Default } from '@digigov/form/inputs/Select/__stories__/Default';
|
package/src/lazy.js
CHANGED
|
@@ -14,11 +14,11 @@ export default {
|
|
|
14
14
|
'ArrayItemHeader': lazy(() => import('@digigov/form/FieldArray/FormDialog').then((module) => ({ default: module['ArrayItemHeader'] }))),
|
|
15
15
|
'ArrayItemDisplay': lazy(() => import('@digigov/form/FieldArray/FormDialog').then((module) => ({ default: module['ArrayItemDisplay'] }))),
|
|
16
16
|
'FieldArray': lazy(() => import('@digigov/form/FieldArray').then((module) => ({ default: module['FieldArray'] }))),
|
|
17
|
+
'FieldObject': lazy(() => import('@digigov/form/FieldObject').then((module) => ({ default: module['FieldObject'] }))),
|
|
17
18
|
'FieldsetWithContext': lazy(() => import('@digigov/form/Fieldset/FieldsetWithContext').then((module) => ({ default: module['FieldsetWithContext'] }))),
|
|
18
19
|
'FieldsetLabel': lazy(() => import('@digigov/form/Fieldset').then((module) => ({ default: module['FieldsetLabel'] }))),
|
|
19
20
|
'FieldsetCaption': lazy(() => import('@digigov/form/Fieldset').then((module) => ({ default: module['FieldsetCaption'] }))),
|
|
20
21
|
'FieldsetBody': lazy(() => import('@digigov/form/Fieldset').then((module) => ({ default: module['FieldsetBody'] }))),
|
|
21
|
-
'FieldObject': lazy(() => import('@digigov/form/FieldObject').then((module) => ({ default: module['FieldObject'] }))),
|
|
22
22
|
'ControlledFormBuilder': lazy(() => import('@digigov/form/FormBuilder').then((module) => ({ default: module['ControlledFormBuilder'] }))),
|
|
23
23
|
'FormBase': lazy(() => import('@digigov/form/FormBuilder').then((module) => ({ default: module['FormBase'] }))),
|
|
24
24
|
'AddObjects': lazy(() => import('@digigov/form/MultiplicityField/add-objects').then((module) => ({ default: module['AddObjects'] }))),
|
package/src/registry.js
CHANGED
|
@@ -12,10 +12,10 @@ import * as _digigov_form_Field from "@digigov/form/Field";
|
|
|
12
12
|
import * as _digigov_form_Field_types from "@digigov/form/Field/types";
|
|
13
13
|
import * as _digigov_form_FieldArray_FormDialog from "@digigov/form/FieldArray/FormDialog";
|
|
14
14
|
import * as _digigov_form_FieldArray from "@digigov/form/FieldArray";
|
|
15
|
+
import * as _digigov_form_FieldObject from "@digigov/form/FieldObject";
|
|
15
16
|
import * as _digigov_form_Fieldset_FieldsetWithContext from "@digigov/form/Fieldset/FieldsetWithContext";
|
|
16
17
|
import * as _digigov_form_Fieldset from "@digigov/form/Fieldset";
|
|
17
18
|
import * as _digigov_form_Fieldset_types from "@digigov/form/Fieldset/types";
|
|
18
|
-
import * as _digigov_form_FieldObject from "@digigov/form/FieldObject";
|
|
19
19
|
import * as _digigov_form_FormBuilder from "@digigov/form/FormBuilder";
|
|
20
20
|
import * as _digigov_form_MultiplicityField_add_objects from "@digigov/form/MultiplicityField/add-objects";
|
|
21
21
|
import * as _digigov_form_MultiplicityField from "@digigov/form/MultiplicityField";
|
|
@@ -46,13 +46,12 @@ import * as _digigov_form_Questions_Step_getAddMoreFields from "@digigov/form/Qu
|
|
|
46
46
|
import * as _digigov_form_Questions_Step from "@digigov/form/Questions/Step";
|
|
47
47
|
import * as _digigov_form_Questions_Step_types from "@digigov/form/Questions/Step/types";
|
|
48
48
|
import * as _digigov_form_inputs_AutoCompleteInput from "@digigov/form/inputs/AutoCompleteInput";
|
|
49
|
-
import * as _digigov_form_inputs_DateInput from "@digigov/form/inputs/DateInput";
|
|
50
49
|
import * as _digigov_form_inputs_Checkboxes from "@digigov/form/inputs/Checkboxes";
|
|
50
|
+
import * as _digigov_form_inputs_DateInput from "@digigov/form/inputs/DateInput";
|
|
51
51
|
import * as _digigov_form_inputs_DateTimeInput from "@digigov/form/inputs/DateTimeInput";
|
|
52
52
|
import * as _digigov_form_inputs_FileInput from "@digigov/form/inputs/FileInput";
|
|
53
53
|
import * as _digigov_form_inputs_ImageInput from "@digigov/form/inputs/ImageInput";
|
|
54
54
|
import * as _digigov_form_inputs_Input from "@digigov/form/inputs/Input";
|
|
55
|
-
import * as _digigov_form_inputs_Input_inputsInputScenarios from "@digigov/form/inputs/Input/inputsInputScenarios";
|
|
56
55
|
import * as _digigov_form_inputs_Label from "@digigov/form/inputs/Label";
|
|
57
56
|
import * as _digigov_form_inputs_OtpInput from "@digigov/form/inputs/OtpInput";
|
|
58
57
|
import * as _digigov_form_inputs_Radio from "@digigov/form/inputs/Radio";
|
|
@@ -104,10 +103,10 @@ export default {
|
|
|
104
103
|
'@digigov/form/Field/types': lazyImport(_digigov_form_Field_types),
|
|
105
104
|
'@digigov/form/FieldArray/FormDialog': lazyImport(_digigov_form_FieldArray_FormDialog),
|
|
106
105
|
'@digigov/form/FieldArray': lazyImport(_digigov_form_FieldArray),
|
|
106
|
+
'@digigov/form/FieldObject': lazyImport(_digigov_form_FieldObject),
|
|
107
107
|
'@digigov/form/Fieldset/FieldsetWithContext': lazyImport(_digigov_form_Fieldset_FieldsetWithContext),
|
|
108
108
|
'@digigov/form/Fieldset': lazyImport(_digigov_form_Fieldset),
|
|
109
109
|
'@digigov/form/Fieldset/types': lazyImport(_digigov_form_Fieldset_types),
|
|
110
|
-
'@digigov/form/FieldObject': lazyImport(_digigov_form_FieldObject),
|
|
111
110
|
'@digigov/form/FormBuilder': lazyImport(_digigov_form_FormBuilder),
|
|
112
111
|
'@digigov/form/MultiplicityField/add-objects': lazyImport(_digigov_form_MultiplicityField_add_objects),
|
|
113
112
|
'@digigov/form/MultiplicityField': lazyImport(_digigov_form_MultiplicityField),
|
|
@@ -138,13 +137,12 @@ export default {
|
|
|
138
137
|
'@digigov/form/Questions/Step': lazyImport(_digigov_form_Questions_Step),
|
|
139
138
|
'@digigov/form/Questions/Step/types': lazyImport(_digigov_form_Questions_Step_types),
|
|
140
139
|
'@digigov/form/inputs/AutoCompleteInput': lazyImport(_digigov_form_inputs_AutoCompleteInput),
|
|
141
|
-
'@digigov/form/inputs/DateInput': lazyImport(_digigov_form_inputs_DateInput),
|
|
142
140
|
'@digigov/form/inputs/Checkboxes': lazyImport(_digigov_form_inputs_Checkboxes),
|
|
141
|
+
'@digigov/form/inputs/DateInput': lazyImport(_digigov_form_inputs_DateInput),
|
|
143
142
|
'@digigov/form/inputs/DateTimeInput': lazyImport(_digigov_form_inputs_DateTimeInput),
|
|
144
143
|
'@digigov/form/inputs/FileInput': lazyImport(_digigov_form_inputs_FileInput),
|
|
145
144
|
'@digigov/form/inputs/ImageInput': lazyImport(_digigov_form_inputs_ImageInput),
|
|
146
145
|
'@digigov/form/inputs/Input': lazyImport(_digigov_form_inputs_Input),
|
|
147
|
-
'@digigov/form/inputs/Input/inputsInputScenarios': lazyImport(_digigov_form_inputs_Input_inputsInputScenarios),
|
|
148
146
|
'@digigov/form/inputs/Label': lazyImport(_digigov_form_inputs_Label),
|
|
149
147
|
'@digigov/form/inputs/OtpInput': lazyImport(_digigov_form_inputs_OtpInput),
|
|
150
148
|
'@digigov/form/inputs/Radio': lazyImport(_digigov_form_inputs_Radio),
|
package/src/validators/index.ts
CHANGED
|
@@ -36,7 +36,16 @@ export const getYUPTypeMap = (
|
|
|
36
36
|
): Record<string, any> => {
|
|
37
37
|
const yupTypeMap = {
|
|
38
38
|
file: (field): MixedSchema => {
|
|
39
|
-
return yup
|
|
39
|
+
return yup
|
|
40
|
+
.mixed()
|
|
41
|
+
.transform((value) => {
|
|
42
|
+
if (!value || value.length === 0) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
return value;
|
|
46
|
+
})
|
|
47
|
+
.nullable()
|
|
48
|
+
.test(FILE_MAX_SIZE_VALIDATOR(field));
|
|
40
49
|
},
|
|
41
50
|
string: (field): yup.StringSchema => {
|
|
42
51
|
if (field.trim) {
|
|
@@ -178,21 +187,12 @@ export const getYUPTypeMap = (
|
|
|
178
187
|
field.trim
|
|
179
188
|
? yup.string().trim().test(PHONE_NUMBER_VALIDATOR(field))
|
|
180
189
|
: yup.string().test(PHONE_NUMBER_VALIDATOR(field)),
|
|
181
|
-
'choice:multiple': (
|
|
182
|
-
field
|
|
183
|
-
): yup.ArraySchema<
|
|
190
|
+
'choice:multiple': (): yup.ArraySchema<
|
|
184
191
|
yup.StringSchema<string | undefined, AnyObject, string | undefined>,
|
|
185
192
|
AnyObject,
|
|
186
193
|
(string | undefined)[] | null | undefined,
|
|
187
194
|
(string | undefined)[] | null | undefined
|
|
188
|
-
> =>
|
|
189
|
-
if (field.required) {
|
|
190
|
-
return yup.array().of(yup.string()).min(1, {
|
|
191
|
-
key: 'form.error.required',
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
return yup.array().of(yup.string()).nullable();
|
|
195
|
-
},
|
|
195
|
+
> => yup.array().of(yup.string()).nullable(),
|
|
196
196
|
'choice:single': (): StringSchema<
|
|
197
197
|
string | null | undefined,
|
|
198
198
|
AnyObject,
|
|
@@ -239,5 +239,5 @@ export function useValidationSchema(
|
|
|
239
239
|
return useMemo(() => {
|
|
240
240
|
const yupTypeMap = getYUPTypeMap(validatorRegistry);
|
|
241
241
|
return getYupObjectShape(fields, yupTypeMap, validatorRegistry);
|
|
242
|
-
}, []);
|
|
242
|
+
}, [fields, validatorRegistry]);
|
|
243
243
|
}
|
|
@@ -12,9 +12,12 @@ const getDate = (v: string) => {
|
|
|
12
12
|
return DATE_CACHE[v] ? DATE_CACHE[v] : dayjs(v, VALID_DATE_FORMATS, true);
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
+
const getDaysInMonth = (month: number, year: number): number => {
|
|
16
|
+
return dayjs(`${year}-${month}-01`).daysInMonth(); // e.g. 29 for Feb 2024
|
|
17
|
+
};
|
|
18
|
+
|
|
15
19
|
// Function to check partial date completion
|
|
16
20
|
const checkPartialDate = (value: string) => {
|
|
17
|
-
console.log("value.split('/')", value.split('/'));
|
|
18
21
|
const [day, month, year] = value.split('/');
|
|
19
22
|
if (day && !month && !year) {
|
|
20
23
|
return 'form.error.date.invalid_month_year';
|
|
@@ -33,9 +36,25 @@ const checkPartialDate = (value: string) => {
|
|
|
33
36
|
}
|
|
34
37
|
if (!day && month && year) {
|
|
35
38
|
return 'form.error.date.invalid_day';
|
|
36
|
-
} else {
|
|
37
|
-
return 'form.error.date.invalid';
|
|
38
39
|
}
|
|
40
|
+
if (day && month) {
|
|
41
|
+
const dayNum = parseInt(day);
|
|
42
|
+
const monthNum = parseInt(month);
|
|
43
|
+
const yearNum = parseInt(year);
|
|
44
|
+
const maxDay = getDaysInMonth(monthNum, yearNum);
|
|
45
|
+
if (dayNum < 1 || dayNum > maxDay) {
|
|
46
|
+
return {
|
|
47
|
+
key: 'form.error.date.invalid_day_range',
|
|
48
|
+
context: {
|
|
49
|
+
maxDay: maxDay,
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (monthNum < 1 || monthNum > 12) {
|
|
54
|
+
return 'form.error.datetime.invalid_month_range';
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return 'form.error.date.invalid';
|
|
39
58
|
};
|
|
40
59
|
|
|
41
60
|
export const LATER_THAN_VALIDATOR = (field: FieldSpec): ValidatorSchema => {
|
|
@@ -96,7 +115,7 @@ export const EARLIER_THAN_VALIDATOR = (field: FieldSpec): ValidatorSchema => {
|
|
|
96
115
|
|
|
97
116
|
export const DATE_VALIDATOR = {
|
|
98
117
|
name: 'date-validator',
|
|
99
|
-
message: (v): string => {
|
|
118
|
+
message: (v): string | object => {
|
|
100
119
|
return checkPartialDate(v.value);
|
|
101
120
|
},
|
|
102
121
|
test: function (value: string) {
|
|
@@ -14,54 +14,141 @@ const getDateTime = (v: string) => {
|
|
|
14
14
|
: dayjs(v, VALID_DATETIME_FORMATS, true);
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
const getDaysInMonth = (month: number, year: number): number => {
|
|
18
|
+
return dayjs(`${year}-${month}-01`).daysInMonth(); // e.g. 29 for Feb 2024
|
|
19
|
+
};
|
|
20
|
+
|
|
18
21
|
const checkPartialDateTime = (value: string) => {
|
|
19
22
|
const [datePart, timePart] = value.split(' ');
|
|
20
|
-
const [day, month, year] = datePart
|
|
21
|
-
const [hours, minutes] = timePart
|
|
23
|
+
const [day, month, year] = datePart?.split('/') ?? [];
|
|
24
|
+
const [hours, minutes] = timePart?.split(':') ?? [];
|
|
22
25
|
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
const hasDay = Boolean(day);
|
|
27
|
+
const hasMonth = Boolean(month);
|
|
28
|
+
const hasYear = Boolean(year);
|
|
29
|
+
const hasHours = Boolean(hours);
|
|
30
|
+
const hasMinutes = Boolean(minutes);
|
|
31
|
+
|
|
32
|
+
if (hasDay && !hasMonth && !hasYear && !hasHours && !hasMinutes) {
|
|
33
|
+
return 'form.error.datetime.invalid_month_year_hours_minutes';
|
|
34
|
+
}
|
|
35
|
+
if (!hasDay && hasMonth && !hasYear && !hasHours && !hasMinutes) {
|
|
36
|
+
return 'form.error.datetime.invalid_day_year_hours_minutes';
|
|
37
|
+
}
|
|
38
|
+
if (!hasDay && !hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
39
|
+
return 'form.error.datetime.invalid_day_month_hours_minutes';
|
|
40
|
+
}
|
|
41
|
+
if (hasDay && hasMonth && !hasYear && !hasHours && !hasMinutes) {
|
|
42
|
+
return 'form.error.datetime.invalid_year_hours_minutes';
|
|
43
|
+
}
|
|
44
|
+
if (hasDay && !hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
45
|
+
return 'form.error.datetime.invalid_month_hours_minutes';
|
|
46
|
+
}
|
|
47
|
+
if (!hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
48
|
+
return 'form.error.datetime.invalid_day_hours_minutes';
|
|
49
|
+
}
|
|
50
|
+
if (hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
51
|
+
return 'form.error.datetime.invalid__hours_minutes';
|
|
52
|
+
}
|
|
53
|
+
if (hasDay && hasMonth && hasYear && hasHours && !hasMinutes) {
|
|
54
|
+
return 'form.error.datetime.invalid_minutes';
|
|
55
|
+
}
|
|
56
|
+
if (hasDay && hasMonth && hasYear && !hasHours && hasMinutes) {
|
|
57
|
+
return 'form.error.datetime.invalid_hours';
|
|
58
|
+
}
|
|
59
|
+
if (hasDay && !hasMonth && !hasYear && hasHours && !hasMinutes) {
|
|
60
|
+
return 'form.error.datetime.invalid_month_year_minutes';
|
|
61
|
+
}
|
|
62
|
+
if (hasDay && !hasMonth && !hasYear && !hasHours && hasMinutes) {
|
|
63
|
+
return 'form.error.datetime.invalid_month_year_hours';
|
|
64
|
+
}
|
|
65
|
+
if (hasDay && !hasMonth && !hasYear && hasHours && hasMinutes) {
|
|
25
66
|
return 'form.error.datetime.invalid_month_year';
|
|
26
67
|
}
|
|
27
|
-
if (!
|
|
68
|
+
if (!hasDay && hasMonth && !hasYear && hasHours && !hasMinutes) {
|
|
69
|
+
return 'form.error.datetime.invalid_day_year_minutes';
|
|
70
|
+
}
|
|
71
|
+
if (!hasDay && hasMonth && !hasYear && !hasHours && hasMinutes) {
|
|
72
|
+
return 'form.error.datetime.invalid_day_year_hours';
|
|
73
|
+
}
|
|
74
|
+
if (!hasDay && hasMonth && !hasYear && hasHours && hasMinutes) {
|
|
28
75
|
return 'form.error.datetime.invalid_day_year';
|
|
29
76
|
}
|
|
30
|
-
if (!
|
|
77
|
+
if (!hasDay && !hasMonth && hasYear && hasHours && !hasMinutes) {
|
|
78
|
+
return 'form.error.datetime.invalid_day_month_minutes';
|
|
79
|
+
}
|
|
80
|
+
if (!hasDay && !hasMonth && hasYear && !hasHours && hasMinutes) {
|
|
81
|
+
return 'form.error.datetime.invalid_day_month_hours';
|
|
82
|
+
}
|
|
83
|
+
if (!hasDay && !hasMonth && hasYear && hasHours && hasMinutes) {
|
|
31
84
|
return 'form.error.datetime.invalid_day_month';
|
|
32
85
|
}
|
|
33
|
-
if (
|
|
86
|
+
if (!hasDay && !hasMonth && !hasYear && hasHours && hasMinutes) {
|
|
87
|
+
return 'form.error.datetime.invalid_day_month_year';
|
|
88
|
+
}
|
|
89
|
+
if (!hasDay && !hasMonth && !hasYear && !hasHours && hasMinutes) {
|
|
90
|
+
return 'form.error.datetime.invalid_day_month_year_hours';
|
|
91
|
+
}
|
|
92
|
+
if (hasDay && hasMonth && !hasYear && hasHours && !hasMinutes) {
|
|
93
|
+
return 'form.error.datetime.invalid_year_minutes';
|
|
94
|
+
}
|
|
95
|
+
if (hasDay && hasMonth && !hasYear && !hasHours && hasMinutes) {
|
|
96
|
+
return 'form.error.datetime.invalid_year_hours';
|
|
97
|
+
}
|
|
98
|
+
if (hasDay && hasMonth && !hasYear && hasHours && hasMinutes) {
|
|
34
99
|
return 'form.error.datetime.invalid_year';
|
|
35
100
|
}
|
|
36
|
-
if (
|
|
101
|
+
if (hasDay && !hasMonth && hasYear && hasHours && !hasMinutes) {
|
|
102
|
+
return 'form.error.datetime.invalid_month_minutes';
|
|
103
|
+
}
|
|
104
|
+
if (hasDay && !hasMonth && hasYear && !hasHours && hasMinutes) {
|
|
105
|
+
return 'form.error.datetime.invalid_month_hours';
|
|
106
|
+
}
|
|
107
|
+
if (hasDay && !hasMonth && hasYear && hasHours && hasMinutes) {
|
|
37
108
|
return 'form.error.datetime.invalid_month';
|
|
38
109
|
}
|
|
39
|
-
if (!
|
|
110
|
+
if (!hasDay && hasMonth && hasYear && hasHours && !hasMinutes) {
|
|
111
|
+
return 'form.error.datetime.invalid_day_minutes';
|
|
112
|
+
}
|
|
113
|
+
if (!hasDay && hasMonth && hasYear && !hasHours && hasMinutes) {
|
|
114
|
+
return 'form.error.datetime.invalid_day_hours';
|
|
115
|
+
}
|
|
116
|
+
if (!hasDay && hasMonth && hasYear && hasHours && hasMinutes) {
|
|
40
117
|
return 'form.error.datetime.invalid_day';
|
|
41
118
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
119
|
+
if (!hasDay && !hasMonth && !hasYear && hasHours && !hasMinutes) {
|
|
120
|
+
return 'form.error.datetime.invalid_day_month_year_minutes';
|
|
121
|
+
}
|
|
122
|
+
if (hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
123
|
+
return 'form.error.datetime.invalid_hours_minutes';
|
|
124
|
+
}
|
|
125
|
+
if (day && month) {
|
|
126
|
+
const dayNum = parseInt(day);
|
|
127
|
+
const monthNum = parseInt(month);
|
|
128
|
+
const yearNum = parseInt(year);
|
|
129
|
+
const maxDay = getDaysInMonth(monthNum, yearNum);
|
|
130
|
+
if (dayNum < 1 || dayNum > maxDay) {
|
|
131
|
+
return {
|
|
132
|
+
key: 'form.error.datetime.invalid_day_range',
|
|
133
|
+
context: {
|
|
134
|
+
maxDay: maxDay,
|
|
135
|
+
},
|
|
136
|
+
};
|
|
46
137
|
}
|
|
47
|
-
if (
|
|
48
|
-
return 'form.error.datetime.
|
|
138
|
+
if (monthNum < 1 || monthNum > 12) {
|
|
139
|
+
return 'form.error.datetime.invalid_month_range';
|
|
49
140
|
}
|
|
50
|
-
|
|
51
|
-
|
|
141
|
+
}
|
|
142
|
+
if (hours && minutes) {
|
|
143
|
+
const hoursNum = parseInt(hours);
|
|
144
|
+
const minutesNum = parseInt(minutes);
|
|
145
|
+
if (hoursNum < 0 || hoursNum > 23) {
|
|
146
|
+
return 'form.error.datetime.invalid_hours_range';
|
|
52
147
|
}
|
|
53
|
-
if (
|
|
54
|
-
|
|
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
|
-
}
|
|
148
|
+
if (minutesNum < 0 || minutesNum > 59) {
|
|
149
|
+
return 'form.error.datetime.invalid_minutes_range';
|
|
62
150
|
}
|
|
63
151
|
}
|
|
64
|
-
|
|
65
152
|
return 'form.error.datetime.invalid';
|
|
66
153
|
};
|
|
67
154
|
|
|
@@ -119,7 +206,7 @@ export const EARLIER_THAN_DATETIME_VALIDATOR = (
|
|
|
119
206
|
|
|
120
207
|
export const DATETIME_VALIDATOR = {
|
|
121
208
|
name: 'datetime-validator',
|
|
122
|
-
message: (v): string => {
|
|
209
|
+
message: (v): string | object => {
|
|
123
210
|
return checkPartialDateTime(v.value);
|
|
124
211
|
},
|
|
125
212
|
test: function (value: string) {
|
package/validators/index.js
CHANGED
|
@@ -25,7 +25,12 @@ import { NUMBER_VALIDATOR } from "@digigov/form/validators/utils/number";
|
|
|
25
25
|
const getYUPTypeMap = (validatorRegistry) => {
|
|
26
26
|
const yupTypeMap = {
|
|
27
27
|
file: (field) => {
|
|
28
|
-
return yup.mixed().
|
|
28
|
+
return yup.mixed().transform((value) => {
|
|
29
|
+
if (!value || value.length === 0) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return value;
|
|
33
|
+
}).nullable().test(FILE_MAX_SIZE_VALIDATOR(field));
|
|
29
34
|
},
|
|
30
35
|
string: (field) => {
|
|
31
36
|
if (field.trim) {
|
|
@@ -105,14 +110,7 @@ const getYUPTypeMap = (validatorRegistry) => {
|
|
|
105
110
|
postal_code: (field) => field.trim ? yup.string().trim().test(POSTALCODE_VALIDATOR(field)) : yup.string().test(POSTALCODE_VALIDATOR(field)),
|
|
106
111
|
mobile_phone: (field) => field.trim ? yup.string().trim().test(MOBILE_PHONE_VALIDATOR) : yup.string().test(MOBILE_PHONE_VALIDATOR),
|
|
107
112
|
phone_number: (field) => field.trim ? yup.string().trim().test(PHONE_NUMBER_VALIDATOR(field)) : yup.string().test(PHONE_NUMBER_VALIDATOR(field)),
|
|
108
|
-
"choice:multiple": (
|
|
109
|
-
if (field.required) {
|
|
110
|
-
return yup.array().of(yup.string()).min(1, {
|
|
111
|
-
key: "form.error.required"
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
return yup.array().of(yup.string()).nullable();
|
|
115
|
-
},
|
|
113
|
+
"choice:multiple": () => yup.array().of(yup.string()).nullable(),
|
|
116
114
|
"choice:single": () => yup.string().nullable(),
|
|
117
115
|
date: (field) => {
|
|
118
116
|
let schema = yup.string().nullable();
|
|
@@ -143,7 +141,7 @@ function useValidationSchema(fields, validatorRegistry) {
|
|
|
143
141
|
return useMemo(() => {
|
|
144
142
|
const yupTypeMap = getYUPTypeMap(validatorRegistry);
|
|
145
143
|
return getYupObjectShape(fields, yupTypeMap, validatorRegistry);
|
|
146
|
-
}, []);
|
|
144
|
+
}, [fields, validatorRegistry]);
|
|
147
145
|
}
|
|
148
146
|
export {
|
|
149
147
|
getYUPTypeMap,
|
package/validators/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/validators/index.ts"],
|
|
4
|
-
"sourcesContent": ["import { MutableRefObject, useMemo } from 'react';\nimport * as yup from 'yup';\nimport { AnyObjectSchema, StringSchema } from 'yup';\nimport { RequiredArraySchema } from 'yup/lib/array';\nimport Lazy from 'yup/lib/Lazy';\nimport { MixedSchema } from 'yup/lib/mixed';\nimport { TypeOfShape, AssertsShape } from 'yup/lib/object';\nimport { AnyObject } from 'yup/lib/types';\nimport { FieldSpec } from '@digigov/form/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\nimport {\n getYupObjectShape,\n AFM_VALIDATOR,\n AMKA_VALIDATOR,\n FILE_MAX_SIZE_VALIDATOR,\n IBAN_VALIDATOR,\n OTP_VALIDATOR,\n MOBILE_PHONE_VALIDATOR,\n PHONE_NUMBER_VALIDATOR,\n TEXT_LIMIT_VALIDATOR,\n POSTALCODE_VALIDATOR,\n UUID4_VALIDATOR,\n IMAGE_DIMENSION_VALIDATOR,\n DATE_VALIDATOR,\n LATER_THAN_VALIDATOR,\n EARLIER_THAN_VALIDATOR,\n DATETIME_VALIDATOR,\n LATER_THAN_DATETIME_VALIDATOR,\n EARLIER_THAN_DATETIME_VALIDATOR,\n} from '@digigov/form/validators/utils';\nimport { INT_VALIDATOR } from '@digigov/form/validators/utils/int';\nimport { NUMBER_VALIDATOR } from '@digigov/form/validators/utils/number';\n\nexport const getYUPTypeMap = (\n validatorRegistry?: Record<string, any>\n): Record<string, any> => {\n const yupTypeMap = {\n file: (field): MixedSchema => {\n return yup.mixed().nullable().test(FILE_MAX_SIZE_VALIDATOR(field));\n },\n string: (field): yup.StringSchema => {\n if (field.trim) {\n return yup.string().trim();\n } else {\n return yup.string();\n }\n },\n boolean: (): yup.BooleanSchema<\n boolean | null | undefined,\n AnyObject,\n boolean | null | undefined\n > => {\n return yup\n .boolean()\n .nullable()\n .transform((value) => {\n if (value === '' || typeof value === 'string') return null;\n if (typeof value === 'boolean') return value;\n if (value === 0 || value === 1) return Boolean(value);\n return value;\n });\n },\n object: (\n field\n ):\n | yup.ObjectSchema<any, AnyObject, TypeOfShape<any>, AssertsShape<any>>\n | Lazy<any, unknown> => {\n return getYupObjectShape(field.extra.fields, yupTypeMap);\n },\n array: (\n field\n ):\n | yup.ArraySchema<any, AnyObject, any[] | undefined>\n | RequiredArraySchema<any, AnyObject, any[] | undefined> => {\n if (typeof field.extra.of === 'object') {\n // else if the field is an object then it is a scalar type\n // eg. number, string etc.\n if (field.required) {\n field.extra.min = 1;\n }\n let arrayValidator = yup\n .array()\n .nullable()\n .of(yupTypeMap[field.extra.of.type](field.extra.of));\n if (field.extra.length)\n arrayValidator = arrayValidator.length(field.extra.length, {\n key: 'form.error.array.length',\n context: {\n length: field.extra.length,\n },\n });\n if (field.extra.min)\n arrayValidator = arrayValidator.min(field.extra.min, {\n key: 'form.error.array.min',\n context: {\n min: field.extra.min,\n },\n });\n if (field.extra.max)\n arrayValidator = arrayValidator.max(field.extra.max, {\n key: 'form.error.array.max',\n context: {\n max: field.extra.max,\n },\n });\n return arrayValidator;\n } else if (typeof field.extra.of === 'string') {\n return yup.array().of(yupTypeMap[field.extra.of]());\n } else {\n // in any other case it will be string\n return yup.array().of(yup.string());\n }\n },\n number: (): MixedSchema =>\n yup\n .mixed()\n .transform((_, val) => (val !== '' ? Number(val) : undefined))\n .test(NUMBER_VALIDATOR()),\n int: (): MixedSchema =>\n yup\n .mixed()\n .transform((_, val) => (val !== '' ? Number(val) : undefined))\n .test(NUMBER_VALIDATOR())\n .test(INT_VALIDATOR()),\n email: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().email('form.error.email')\n : yup.string().email('form.error.email'),\n afm: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().test(AFM_VALIDATOR)\n : yup.string().test(AFM_VALIDATOR),\n amka: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().test(AMKA_VALIDATOR)\n : yup.string().test(AMKA_VALIDATOR),\n uuid4: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().test(UUID4_VALIDATOR)\n : yup.string().test(UUID4_VALIDATOR),\n iban: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().test(IBAN_VALIDATOR(field))\n : yup.string().trim().test(IBAN_VALIDATOR(field)),\n otp: (field): yup.StringSchema =>\n yup.string().trim().test(OTP_VALIDATOR(field)),\n text: (field): yup.StringSchema => {\n if (field?.extra?.limit?.max || !!field?.extra?.limit?.min) {\n return field.trim\n ? yup.string().trim().test(TEXT_LIMIT_VALIDATOR(field))\n : yup.string().test(TEXT_LIMIT_VALIDATOR(field));\n } else {\n return field.trim ? yup.string().trim() : yup.string();\n }\n },\n image: (field): MixedSchema => {\n return yup\n .mixed()\n .transform((value) => {\n if (!value.length || value.length === 0) {\n return null;\n }\n return value;\n })\n .nullable()\n .test(FILE_MAX_SIZE_VALIDATOR(field))\n .test(IMAGE_DIMENSION_VALIDATOR(field));\n },\n postal_code: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().test(POSTALCODE_VALIDATOR(field))\n : yup.string().test(POSTALCODE_VALIDATOR(field)),\n mobile_phone: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().test(MOBILE_PHONE_VALIDATOR)\n : yup.string().test(MOBILE_PHONE_VALIDATOR),\n phone_number: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().test(PHONE_NUMBER_VALIDATOR(field))\n : yup.string().test(PHONE_NUMBER_VALIDATOR(field)),\n 'choice:multiple': (
|
|
5
|
-
"mappings": "AAAA,SAA2B,eAAe;AAC1C,YAAY,SAAS;AASrB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,qBAAqB;AAC9B,SAAS,wBAAwB;AAE1B,MAAM,gBAAgB,CAC3B,sBACwB;AACxB,QAAM,aAAa;AAAA,IACjB,MAAM,CAAC,UAAuB;AAC5B,aAAO,
|
|
4
|
+
"sourcesContent": ["import { MutableRefObject, useMemo } from 'react';\nimport * as yup from 'yup';\nimport { AnyObjectSchema, StringSchema } from 'yup';\nimport { RequiredArraySchema } from 'yup/lib/array';\nimport Lazy from 'yup/lib/Lazy';\nimport { MixedSchema } from 'yup/lib/mixed';\nimport { TypeOfShape, AssertsShape } from 'yup/lib/object';\nimport { AnyObject } from 'yup/lib/types';\nimport { FieldSpec } from '@digigov/form/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\nimport {\n getYupObjectShape,\n AFM_VALIDATOR,\n AMKA_VALIDATOR,\n FILE_MAX_SIZE_VALIDATOR,\n IBAN_VALIDATOR,\n OTP_VALIDATOR,\n MOBILE_PHONE_VALIDATOR,\n PHONE_NUMBER_VALIDATOR,\n TEXT_LIMIT_VALIDATOR,\n POSTALCODE_VALIDATOR,\n UUID4_VALIDATOR,\n IMAGE_DIMENSION_VALIDATOR,\n DATE_VALIDATOR,\n LATER_THAN_VALIDATOR,\n EARLIER_THAN_VALIDATOR,\n DATETIME_VALIDATOR,\n LATER_THAN_DATETIME_VALIDATOR,\n EARLIER_THAN_DATETIME_VALIDATOR,\n} from '@digigov/form/validators/utils';\nimport { INT_VALIDATOR } from '@digigov/form/validators/utils/int';\nimport { NUMBER_VALIDATOR } from '@digigov/form/validators/utils/number';\n\nexport const getYUPTypeMap = (\n validatorRegistry?: Record<string, any>\n): Record<string, any> => {\n const yupTypeMap = {\n file: (field): MixedSchema => {\n return yup\n .mixed()\n .transform((value) => {\n if (!value || value.length === 0) {\n return null;\n }\n return value;\n })\n .nullable()\n .test(FILE_MAX_SIZE_VALIDATOR(field));\n },\n string: (field): yup.StringSchema => {\n if (field.trim) {\n return yup.string().trim();\n } else {\n return yup.string();\n }\n },\n boolean: (): yup.BooleanSchema<\n boolean | null | undefined,\n AnyObject,\n boolean | null | undefined\n > => {\n return yup\n .boolean()\n .nullable()\n .transform((value) => {\n if (value === '' || typeof value === 'string') return null;\n if (typeof value === 'boolean') return value;\n if (value === 0 || value === 1) return Boolean(value);\n return value;\n });\n },\n object: (\n field\n ):\n | yup.ObjectSchema<any, AnyObject, TypeOfShape<any>, AssertsShape<any>>\n | Lazy<any, unknown> => {\n return getYupObjectShape(field.extra.fields, yupTypeMap);\n },\n array: (\n field\n ):\n | yup.ArraySchema<any, AnyObject, any[] | undefined>\n | RequiredArraySchema<any, AnyObject, any[] | undefined> => {\n if (typeof field.extra.of === 'object') {\n // else if the field is an object then it is a scalar type\n // eg. number, string etc.\n if (field.required) {\n field.extra.min = 1;\n }\n let arrayValidator = yup\n .array()\n .nullable()\n .of(yupTypeMap[field.extra.of.type](field.extra.of));\n if (field.extra.length)\n arrayValidator = arrayValidator.length(field.extra.length, {\n key: 'form.error.array.length',\n context: {\n length: field.extra.length,\n },\n });\n if (field.extra.min)\n arrayValidator = arrayValidator.min(field.extra.min, {\n key: 'form.error.array.min',\n context: {\n min: field.extra.min,\n },\n });\n if (field.extra.max)\n arrayValidator = arrayValidator.max(field.extra.max, {\n key: 'form.error.array.max',\n context: {\n max: field.extra.max,\n },\n });\n return arrayValidator;\n } else if (typeof field.extra.of === 'string') {\n return yup.array().of(yupTypeMap[field.extra.of]());\n } else {\n // in any other case it will be string\n return yup.array().of(yup.string());\n }\n },\n number: (): MixedSchema =>\n yup\n .mixed()\n .transform((_, val) => (val !== '' ? Number(val) : undefined))\n .test(NUMBER_VALIDATOR()),\n int: (): MixedSchema =>\n yup\n .mixed()\n .transform((_, val) => (val !== '' ? Number(val) : undefined))\n .test(NUMBER_VALIDATOR())\n .test(INT_VALIDATOR()),\n email: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().email('form.error.email')\n : yup.string().email('form.error.email'),\n afm: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().test(AFM_VALIDATOR)\n : yup.string().test(AFM_VALIDATOR),\n amka: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().test(AMKA_VALIDATOR)\n : yup.string().test(AMKA_VALIDATOR),\n uuid4: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().test(UUID4_VALIDATOR)\n : yup.string().test(UUID4_VALIDATOR),\n iban: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().test(IBAN_VALIDATOR(field))\n : yup.string().trim().test(IBAN_VALIDATOR(field)),\n otp: (field): yup.StringSchema =>\n yup.string().trim().test(OTP_VALIDATOR(field)),\n text: (field): yup.StringSchema => {\n if (field?.extra?.limit?.max || !!field?.extra?.limit?.min) {\n return field.trim\n ? yup.string().trim().test(TEXT_LIMIT_VALIDATOR(field))\n : yup.string().test(TEXT_LIMIT_VALIDATOR(field));\n } else {\n return field.trim ? yup.string().trim() : yup.string();\n }\n },\n image: (field): MixedSchema => {\n return yup\n .mixed()\n .transform((value) => {\n if (!value.length || value.length === 0) {\n return null;\n }\n return value;\n })\n .nullable()\n .test(FILE_MAX_SIZE_VALIDATOR(field))\n .test(IMAGE_DIMENSION_VALIDATOR(field));\n },\n postal_code: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().test(POSTALCODE_VALIDATOR(field))\n : yup.string().test(POSTALCODE_VALIDATOR(field)),\n mobile_phone: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().test(MOBILE_PHONE_VALIDATOR)\n : yup.string().test(MOBILE_PHONE_VALIDATOR),\n phone_number: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().test(PHONE_NUMBER_VALIDATOR(field))\n : yup.string().test(PHONE_NUMBER_VALIDATOR(field)),\n 'choice:multiple': (): yup.ArraySchema<\n yup.StringSchema<string | undefined, AnyObject, string | undefined>,\n AnyObject,\n (string | undefined)[] | null | undefined,\n (string | undefined)[] | null | undefined\n > => yup.array().of(yup.string()).nullable(),\n 'choice:single': (): StringSchema<\n string | null | undefined,\n AnyObject,\n string | null | undefined\n > => yup.string().nullable(),\n date: (\n field\n ): yup.StringSchema<\n string | null | undefined,\n AnyObject,\n string | null | undefined\n > => {\n let schema = yup.string().nullable();\n if (field?.extra?.min) {\n schema = schema.test(LATER_THAN_VALIDATOR(field));\n }\n if (field?.extra?.max) {\n schema = schema.test(EARLIER_THAN_VALIDATOR(field));\n } else {\n schema = schema.test(DATE_VALIDATOR);\n }\n return schema;\n },\n datetime: (field): yup.StringSchema => {\n if (field?.extra?.min) {\n return yup.string().test(LATER_THAN_DATETIME_VALIDATOR(field));\n }\n if (field?.extra?.max) {\n return yup.string().test(EARLIER_THAN_DATETIME_VALIDATOR(field));\n }\n return yup.string().test(DATETIME_VALIDATOR);\n },\n ...validatorRegistry,\n };\n return yupTypeMap;\n};\n\nexport interface MutableRefObjectProps {}\n// Create a yup validation schema from given fields input\nexport function useValidationSchema(\n fields: FieldSpec[] | MutableRefObject<MutableRefObjectProps>,\n validatorRegistry?: Record<string, ValidatorSchema[]>\n): Lazy<any, unknown> | AnyObjectSchema | void {\n return useMemo(() => {\n const yupTypeMap = getYUPTypeMap(validatorRegistry);\n return getYupObjectShape(fields, yupTypeMap, validatorRegistry);\n }, [fields, validatorRegistry]);\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -6,8 +6,10 @@ const DATE_CACHE = {};
|
|
|
6
6
|
const getDate = (v) => {
|
|
7
7
|
return DATE_CACHE[v] ? DATE_CACHE[v] : dayjs(v, VALID_DATE_FORMATS, true);
|
|
8
8
|
};
|
|
9
|
+
const getDaysInMonth = (month, year) => {
|
|
10
|
+
return dayjs(`${year}-${month}-01`).daysInMonth();
|
|
11
|
+
};
|
|
9
12
|
const checkPartialDate = (value) => {
|
|
10
|
-
console.log("value.split('/')", value.split("/"));
|
|
11
13
|
const [day, month, year] = value.split("/");
|
|
12
14
|
if (day && !month && !year) {
|
|
13
15
|
return "form.error.date.invalid_month_year";
|
|
@@ -26,9 +28,25 @@ const checkPartialDate = (value) => {
|
|
|
26
28
|
}
|
|
27
29
|
if (!day && month && year) {
|
|
28
30
|
return "form.error.date.invalid_day";
|
|
29
|
-
} else {
|
|
30
|
-
return "form.error.date.invalid";
|
|
31
31
|
}
|
|
32
|
+
if (day && month) {
|
|
33
|
+
const dayNum = parseInt(day);
|
|
34
|
+
const monthNum = parseInt(month);
|
|
35
|
+
const yearNum = parseInt(year);
|
|
36
|
+
const maxDay = getDaysInMonth(monthNum, yearNum);
|
|
37
|
+
if (dayNum < 1 || dayNum > maxDay) {
|
|
38
|
+
return {
|
|
39
|
+
key: "form.error.date.invalid_day_range",
|
|
40
|
+
context: {
|
|
41
|
+
maxDay
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
if (monthNum < 1 || monthNum > 12) {
|
|
46
|
+
return "form.error.datetime.invalid_month_range";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return "form.error.date.invalid";
|
|
32
50
|
};
|
|
33
51
|
const LATER_THAN_VALIDATOR = (field) => {
|
|
34
52
|
let minDate;
|