@digigov/form 2.0.0-298cfc51 → 2.0.0-32ae417f
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/ErrorGroup/index.js +48 -0
- package/{Form.stories → Field/ErrorGroup}/package.json +1 -1
- package/Field/ErrorGroup.d.ts +15 -0
- package/Field/ErrorGroup.js.map +7 -0
- package/Field/FieldBase/index.js +37 -25
- package/Field/FieldBase.js.map +2 -2
- package/Field/FieldBaseContainer/index.js +37 -17
- package/Field/FieldBaseContainer.d.ts +1 -1
- package/Field/FieldBaseContainer.js.map +2 -2
- package/Field/FieldConditional/index.js +4 -0
- package/Field/FieldConditional.js.map +2 -2
- package/Field/index.js +15 -4
- package/Field/index.js.map +2 -2
- package/Field/types.d.ts +20 -10
- package/Field/utils/index.js +9 -1
- package/Field/utils/index.js.map +2 -2
- package/Field/utils/useField/index.js +14 -1
- package/Field/utils/useField.js.map +2 -2
- package/FieldArray/FieldArray.stories.d.ts +1 -0
- package/FieldArray/FormDialog/index.js +397 -0
- package/{Questions/Questions.stories → FieldArray/FormDialog}/package.json +1 -1
- package/FieldArray/FormDialog.d.ts +66 -0
- package/FieldArray/FormDialog.js.map +7 -0
- package/FieldArray/__stories__/Default.d.ts +1 -1
- package/FieldArray/__stories__/WithExactLength.d.ts +1 -1
- package/FieldArray/__stories__/WithModal.d.ts +2 -0
- package/FieldArray/index.d.ts +6 -0
- package/FieldArray/index.js +84 -26
- package/FieldArray/index.js.map +2 -2
- package/FieldObject/index.d.ts +5 -0
- package/FieldObject/index.js +30 -15
- package/FieldObject/index.js.map +2 -2
- package/FormBuilder/FormBuilder.stories.d.ts +4 -0
- package/FormBuilder/__stories__/AutoErrorGrouping.d.ts +3 -0
- package/FormBuilder/__stories__/Default.d.ts +1 -1
- package/FormBuilder/__stories__/ErrorGrouping.d.ts +3 -0
- package/FormBuilder/index.d.ts +1 -1
- package/FormBuilder/index.js +92 -9
- package/FormBuilder/index.js.map +2 -2
- package/FormBuilder/interaction.test.d.ts +1 -0
- 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 +6 -2
- package/MultiplicityField/add-objects.js.map +2 -2
- package/MultiplicityField/index.js +5 -1
- package/MultiplicityField/index.js.map +2 -2
- package/MultiplicityField/types.d.ts +2 -2
- package/Questions/Questions/index.js +5 -4
- package/Questions/Questions.js.map +2 -2
- package/Questions/Questions.stories.d.ts +2 -0
- package/Questions/Step/StepArrayReview.js.map +2 -2
- package/Questions/__stories__/Default.d.ts +1 -1
- package/cjs/Field/ErrorGroup/index.js +82 -0
- package/cjs/Field/ErrorGroup.js.map +7 -0
- package/cjs/Field/FieldBase/index.js +36 -24
- package/cjs/Field/FieldBase.js.map +2 -2
- package/cjs/Field/FieldBaseContainer/index.js +36 -16
- package/cjs/Field/FieldBaseContainer.js.map +3 -3
- package/cjs/Field/FieldConditional/index.js +4 -0
- package/cjs/Field/FieldConditional.js.map +2 -2
- package/cjs/Field/index.js +15 -4
- package/cjs/Field/index.js.map +2 -2
- package/cjs/Field/types.js.map +1 -1
- package/cjs/Field/utils/index.js +9 -1
- package/cjs/Field/utils/index.js.map +3 -3
- package/cjs/Field/utils/useField/index.js +14 -1
- package/cjs/Field/utils/useField.js.map +2 -2
- package/cjs/FieldArray/FormDialog/index.js +416 -0
- package/cjs/FieldArray/FormDialog.js.map +7 -0
- package/cjs/FieldArray/index.js +82 -24
- package/cjs/FieldArray/index.js.map +3 -3
- package/cjs/FieldObject/index.js +30 -15
- package/cjs/FieldObject/index.js.map +2 -2
- package/cjs/FormBuilder/index.js +92 -9
- package/cjs/FormBuilder/index.js.map +2 -2
- package/cjs/FormContext/index.js +9 -4
- package/cjs/FormContext.js.map +3 -3
- package/cjs/MultiplicityField/add-objects/index.js +6 -2
- package/cjs/MultiplicityField/add-objects.js.map +2 -2
- package/cjs/MultiplicityField/index.js +5 -1
- package/cjs/MultiplicityField/index.js.map +2 -2
- package/cjs/MultiplicityField/types.js.map +1 -1
- package/cjs/Questions/Questions/index.js +5 -4
- package/cjs/Questions/Questions.js.map +2 -2
- package/cjs/Questions/Step/StepArrayReview.js.map +2 -2
- package/cjs/inputs/AutoCompleteInput/index.js +4 -3
- package/cjs/inputs/AutoCompleteInput/index.js.map +2 -2
- package/cjs/inputs/Checkboxes/index.js +3 -1
- package/cjs/inputs/Checkboxes/index.js.map +2 -2
- package/cjs/inputs/DateInput/index.js +48 -18
- package/cjs/inputs/DateInput/index.js.map +2 -2
- package/cjs/inputs/DateTimeInput/index.js +245 -0
- package/cjs/inputs/DateTimeInput/index.js.map +7 -0
- package/cjs/inputs/FileInput/index.js +68 -30
- 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 +48 -11
- package/cjs/inputs/ImageInput/index.js.map +2 -2
- package/cjs/inputs/Input/index.js +10 -2
- package/cjs/inputs/Input/index.js.map +2 -2
- package/cjs/inputs/Label/index.js.map +2 -2
- package/cjs/inputs/OtpInput/index.js +1 -0
- package/cjs/inputs/OtpInput/index.js.map +2 -2
- package/cjs/inputs/Radio/index.js +1 -0
- package/cjs/inputs/Radio/index.js.map +2 -2
- package/cjs/inputs/Select/index.js +9 -2
- package/cjs/inputs/Select/index.js.map +2 -2
- package/cjs/inputs/inputsScenarios/index.js +6 -12
- package/cjs/inputs/inputsScenarios.js.map +2 -2
- package/cjs/{lazy/index.js → lazy.js} +48 -37
- package/cjs/lazy.js.map +3 -3
- package/cjs/locales/el.js.map +1 -1
- package/cjs/{registry/index.js → registry.js} +68 -60
- package/cjs/registry.js.map +3 -3
- package/cjs/types.js.map +1 -1
- package/cjs/utils/index.js +22 -7
- package/cjs/utils.js.map +2 -2
- package/cjs/validators/index.js +39 -19
- package/cjs/validators/index.js.map +2 -2
- package/cjs/validators/utils/amka/index.js +60 -0
- package/cjs/validators/utils/amka.js.map +7 -0
- package/cjs/validators/utils/date/index.js +27 -4
- package/cjs/validators/utils/date.js.map +2 -2
- package/cjs/validators/utils/datetime/index.js +245 -0
- package/cjs/validators/utils/datetime.js.map +7 -0
- package/cjs/validators/utils/file/index.js +30 -17
- package/cjs/validators/utils/file.js.map +2 -2
- package/cjs/validators/utils/index.js +8 -2
- package/cjs/validators/utils/index.js.map +2 -2
- package/cjs/validators/utils/int/index.js +1 -1
- package/cjs/validators/utils/int.js.map +2 -2
- package/cjs/validators/utils/number/index.js +1 -1
- package/cjs/validators/utils/number.js.map +2 -2
- package/cjs/validators/utils/phone.js.map +2 -2
- package/cjs/validators/utils/postal_code.js.map +1 -1
- package/cjs/validators/utils/uuid4.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/AutoCompleteInput/index.d.ts +1 -1
- package/inputs/AutoCompleteInput/index.js +4 -3
- package/inputs/AutoCompleteInput/index.js.map +2 -2
- 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.d.ts +1 -1
- package/inputs/Checkboxes/index.js +3 -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.d.ts +1 -2
- package/inputs/DateInput/index.js +49 -19
- package/inputs/DateInput/index.js.map +2 -2
- package/inputs/DateTimeInput/DateTimeInput.stories.d.ts +14 -0
- package/inputs/DateTimeInput/__stories__/Default.d.ts +3 -0
- 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.d.ts +13 -0
- package/inputs/DateTimeInput/index.js +215 -0
- package/inputs/DateTimeInput/index.js.map +7 -0
- package/inputs/DateTimeInput/index.test.d.ts +1 -0
- package/inputs/{Input/Input.stories → DateTimeInput}/package.json +1 -1
- package/inputs/FileInput/FileInput.stories.d.ts +3 -0
- package/inputs/FileInput/__stories__/Default.d.ts +1 -1
- package/inputs/FileInput/__stories__/WithBorderAndLink.d.ts +3 -0
- package/inputs/FileInput/index.d.ts +17 -1
- package/inputs/FileInput/index.js +73 -32
- 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/{DateInput/__stories__/Default → 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 +49 -12
- package/inputs/ImageInput/index.js.map +2 -2
- package/inputs/Input/Input.stories.d.ts +5 -0
- package/inputs/Input/__stories__/AFM.d.ts +1 -1
- package/inputs/Input/__stories__/AMKA.d.ts +3 -0
- 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 +3 -0
- package/inputs/Input/__stories__/TextWithLimit.d.ts +1 -1
- package/inputs/Input/index.d.ts +2 -1
- package/inputs/Input/index.js +10 -2
- 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/Label/index.d.ts +0 -2
- package/inputs/Label/index.js.map +2 -2
- package/inputs/OtpInput/OtpInput.stories.d.ts +2 -0
- package/inputs/OtpInput/__stories__/Default.d.ts +1 -1
- package/inputs/OtpInput/index.js +1 -0
- package/inputs/OtpInput/index.js.map +2 -2
- 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/Radio/index.d.ts +1 -1
- package/inputs/Radio/index.js +1 -0
- package/inputs/Radio/index.js.map +2 -2
- package/inputs/Select/Select.stories.d.ts +2 -0
- package/inputs/Select/__stories__/Default.d.ts +1 -1
- package/inputs/Select/index.d.ts +3 -2
- package/inputs/Select/index.js +13 -3
- package/inputs/Select/index.js.map +2 -2
- package/inputs/inputsScenarios/index.js +6 -12
- package/inputs/inputsScenarios.d.ts +1 -1
- package/inputs/inputsScenarios.js.map +2 -2
- package/lazy/index.js +77 -70
- package/locales/el.js.map +1 -1
- package/package.json +8 -8
- package/registry/index.js +114 -107
- package/src/Field/ErrorGroup.tsx +84 -0
- package/src/Field/FieldBase.tsx +39 -24
- package/src/Field/FieldBaseContainer.tsx +69 -46
- package/src/Field/FieldConditional.tsx +6 -2
- package/src/Field/doc.mdx +202 -1
- package/src/Field/index.tsx +20 -5
- package/src/Field/types.tsx +41 -29
- package/src/Field/utils/index.ts +8 -0
- package/src/Field/utils/useField.ts +14 -2
- package/src/FieldArray/FieldArray.stories.js +1 -0
- package/src/FieldArray/FormDialog.tsx +565 -0
- package/src/FieldArray/__stories__/Default.tsx +2 -1
- package/src/FieldArray/__stories__/WithExactLength.tsx +2 -1
- package/src/FieldArray/__stories__/WithModal.tsx +160 -0
- package/src/FieldArray/index.test.tsx +8 -0
- package/src/FieldArray/index.tsx +114 -50
- package/src/FieldObject/index.tsx +39 -18
- package/src/FormBuilder/FormBuilder.stories.js +5 -0
- package/src/FormBuilder/__stories__/AutoErrorGrouping.tsx +63 -0
- package/src/FormBuilder/__stories__/Default.tsx +1 -1
- package/src/FormBuilder/__stories__/ErrorGrouping.tsx +43 -0
- package/src/FormBuilder/doc.mdx +9 -4
- package/src/FormBuilder/index.test.tsx +12 -0
- package/src/FormBuilder/index.tsx +102 -12
- package/src/FormBuilder/interaction.test.tsx +40 -0
- package/src/FormBuilder/scenarios.test.tsx +1002 -130
- package/src/FormContext.tsx +5 -2
- 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 +6 -3
- package/src/MultiplicityField/doc.mdx +101 -83
- package/src/MultiplicityField/index.test.tsx +4 -0
- package/src/MultiplicityField/index.tsx +4 -0
- package/src/MultiplicityField/types.ts +2 -2
- package/src/Questions/Questions.stories.js +3 -0
- package/src/Questions/Questions.tsx +4 -4
- package/src/Questions/Step/StepArrayReview.tsx +1 -1
- package/src/Questions/__snapshots__/index.spec.tsx.snap +3 -1
- package/src/Questions/__stories__/Default.tsx +1 -1
- package/src/Questions/doc.mdx +21 -41
- package/src/Questions/index.spec.tsx +14 -2
- package/src/Questions/index.test.tsx +4 -0
- package/src/doc.mdx +26 -11
- package/src/inputs/AutoCompleteInput/AutoComplete.stories.js +3 -0
- package/src/inputs/AutoCompleteInput/__stories__/Default.tsx +3 -11
- package/src/inputs/AutoCompleteInput/__stories__/Multiple.tsx +2 -8
- package/src/inputs/AutoCompleteInput/index.test.tsx +4 -0
- package/src/inputs/AutoCompleteInput/index.tsx +4 -5
- 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.test.tsx +4 -0
- package/src/inputs/Checkboxes/index.tsx +4 -6
- package/src/inputs/DateInput/DateInput.stories.js +7 -0
- package/src/inputs/DateInput/__stories__/Default.tsx +8 -13
- 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 +20 -0
- package/src/inputs/DateInput/index.tsx +53 -18
- package/src/inputs/DateTimeInput/DateTimeInput.stories.js +14 -0
- package/src/inputs/DateTimeInput/__stories__/Default.tsx +25 -0
- 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/doc.mdx +16 -0
- package/src/inputs/DateTimeInput/index.test.tsx +40 -0
- package/src/inputs/DateTimeInput/index.tsx +233 -0
- package/src/inputs/FileInput/FileInput.stories.js +4 -0
- package/src/inputs/FileInput/__stories__/Default.tsx +1 -1
- package/src/inputs/FileInput/__stories__/WithBorderAndLink.tsx +34 -0
- package/src/inputs/FileInput/index.test.tsx +8 -0
- package/src/inputs/FileInput/index.tsx +104 -38
- package/src/inputs/ImageInput/ImageInput.stories.js +5 -2
- package/src/inputs/ImageInput/__stories__/Default.tsx +1 -1
- package/src/inputs/ImageInput/__stories__/MaxSize.tsx +5 -4
- package/src/inputs/ImageInput/__stories__/{WithInvalidImageSize.tsx → WithInitialValues.tsx} +12 -3
- 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 +8 -4
- package/src/inputs/ImageInput/index.tsx +97 -42
- package/src/inputs/Input/Input.stories.js +6 -0
- package/src/inputs/Input/__stories__/AFM.tsx +1 -1
- package/src/inputs/Input/__stories__/AMKA.tsx +23 -0
- 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 +2 -2
- package/src/inputs/Input/__stories__/MobilePhone.tsx +2 -2
- package/src/inputs/Input/__stories__/PhoneNumber.tsx +2 -2
- package/src/inputs/Input/__stories__/PostalCode.tsx +2 -2
- package/src/inputs/Input/__stories__/String.tsx +1 -1
- package/src/inputs/Input/__stories__/StringWithTrimValidation.tsx +26 -0
- package/src/inputs/Input/__stories__/TextWithLimit.tsx +2 -1
- package/src/inputs/Input/index.test.tsx +16 -0
- package/src/inputs/Input/index.tsx +13 -3
- package/src/inputs/Label/Label.stories.js +3 -0
- package/src/inputs/Label/__stories__/Default.tsx +1 -1
- package/src/inputs/Label/index.test.tsx +4 -0
- package/src/inputs/Label/index.tsx +0 -3
- package/src/inputs/OtpInput/OtpInput.stories.js +3 -0
- package/src/inputs/OtpInput/__stories__/Default.tsx +1 -1
- package/src/inputs/OtpInput/index.test.tsx +4 -0
- package/src/inputs/OtpInput/index.tsx +3 -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/Radio/index.test.tsx +4 -0
- package/src/inputs/Radio/index.tsx +2 -1
- package/src/inputs/Select/Select.stories.js +3 -0
- package/src/inputs/Select/__stories__/Default.tsx +1 -1
- package/src/inputs/Select/index.test.tsx +4 -0
- package/src/inputs/Select/index.tsx +18 -6
- package/src/inputs/inputsScenarios.ts +36 -42
- package/src/lazy.js +77 -67
- package/src/locales/el.ts +1 -1
- package/src/registry.js +106 -100
- package/src/types.tsx +4 -3
- package/src/utils.ts +29 -8
- package/src/validators/index.ts +70 -20
- package/src/validators/utils/amka.ts +39 -0
- package/src/validators/utils/date.ts +29 -5
- package/src/validators/utils/datetime.ts +228 -0
- package/src/validators/utils/file.ts +33 -17
- package/src/validators/utils/index.ts +5 -1
- package/src/validators/utils/int.ts +1 -1
- package/src/validators/utils/number.ts +1 -1
- package/src/validators/utils/phone.ts +1 -1
- package/src/validators/utils/postal_code.ts +1 -1
- package/src/validators/utils/uuid4.ts +2 -1
- package/src/validators/validators.spec.ts +3 -3
- package/types.d.ts +4 -3
- package/types.js.map +1 -1
- package/utils/index.js +22 -7
- package/utils.d.ts +2 -0
- package/utils.js.map +2 -2
- package/validators/index.d.ts +1 -1
- package/validators/index.js +44 -20
- package/validators/index.js.map +2 -2
- package/validators/utils/amka/index.js +36 -0
- package/{FieldArray/FieldArray.stories → validators/utils/amka}/package.json +1 -1
- package/validators/utils/amka.d.ts +6 -0
- package/validators/utils/amka.js.map +7 -0
- package/validators/utils/date/index.js +27 -4
- package/validators/utils/date.d.ts +1 -1
- package/validators/utils/date.js.map +2 -2
- package/validators/utils/datetime/index.js +210 -0
- package/validators/utils/datetime/package.json +6 -0
- package/validators/utils/datetime.d.ts +9 -0
- package/validators/utils/datetime.js.map +7 -0
- package/validators/utils/file/index.js +30 -17
- package/validators/utils/file.js.map +2 -2
- package/validators/utils/index.d.ts +2 -0
- package/validators/utils/index.js +5 -1
- package/validators/utils/index.js.map +2 -2
- package/validators/utils/int/index.js +1 -1
- package/validators/utils/int.js.map +2 -2
- package/validators/utils/number/index.js +1 -1
- package/validators/utils/number.js.map +2 -2
- package/validators/utils/phone.d.ts +1 -1
- package/validators/utils/phone.js.map +2 -2
- package/validators/utils/postal_code.d.ts +1 -1
- package/validators/utils/postal_code.js.map +1 -1
- package/validators/utils/uuid4.js.map +2 -2
- package/FieldArray/FieldArray.stories/index.js +0 -14
- package/FieldArray/FieldArray.stories.js.map +0 -7
- package/FieldArray/__stories__/Default/index.js +0 -95
- package/FieldArray/__stories__/Default/package.json +0 -6
- package/FieldArray/__stories__/Default.js.map +0 -7
- package/FieldArray/__stories__/WithExactLength/index.js +0 -95
- package/FieldArray/__stories__/WithExactLength/package.json +0 -6
- package/FieldArray/__stories__/WithExactLength.js.map +0 -7
- package/Form.stories/index.js +0 -7
- package/Form.stories.js.map +0 -7
- package/FormBuilder/FormBuilder.stories/index.js +0 -12
- package/FormBuilder/FormBuilder.stories/package.json +0 -6
- package/FormBuilder/FormBuilder.stories.js.map +0 -7
- package/FormBuilder/__stories__/Default/index.js +0 -32
- package/FormBuilder/__stories__/Default/package.json +0 -6
- package/FormBuilder/__stories__/Default.js.map +0 -7
- package/MultiplicityField/MultiplicityField.stories/index.js +0 -22
- package/MultiplicityField/MultiplicityField.stories/package.json +0 -6
- package/MultiplicityField/MultiplicityField.stories.js.map +0 -7
- package/MultiplicityField/__stories__/Default/index.js +0 -100
- package/MultiplicityField/__stories__/Default/package.json +0 -6
- package/MultiplicityField/__stories__/Default.js.map +0 -7
- package/MultiplicityField/__stories__/PreviewDisplay/index.js +0 -70
- package/MultiplicityField/__stories__/PreviewDisplay/package.json +0 -6
- package/MultiplicityField/__stories__/PreviewDisplay.js.map +0 -7
- package/MultiplicityField/__stories__/WithExactLength/index.js +0 -97
- package/MultiplicityField/__stories__/WithExactLength/package.json +0 -6
- package/MultiplicityField/__stories__/WithExactLength.js.map +0 -7
- package/MultiplicityField/__stories__/WithMaxLength/index.js +0 -100
- package/MultiplicityField/__stories__/WithMaxLength/package.json +0 -6
- package/MultiplicityField/__stories__/WithMaxLength.js.map +0 -7
- package/MultiplicityField/__stories__/WithMinAndMaxLength/index.js +0 -101
- package/MultiplicityField/__stories__/WithMinAndMaxLength/package.json +0 -6
- package/MultiplicityField/__stories__/WithMinAndMaxLength.js.map +0 -7
- package/MultiplicityField/__stories__/WithMinLength/index.js +0 -100
- package/MultiplicityField/__stories__/WithMinLength/package.json +0 -6
- package/MultiplicityField/__stories__/WithMinLength.js.map +0 -7
- package/Questions/Questions.stories/index.js +0 -12
- package/Questions/Questions.stories.js.map +0 -7
- package/Questions/__stories__/Default/index.js +0 -108
- package/Questions/__stories__/Default/package.json +0 -6
- package/Questions/__stories__/Default.js.map +0 -7
- package/cjs/FieldArray/FieldArray.stories/index.js +0 -48
- package/cjs/FieldArray/FieldArray.stories.js.map +0 -7
- package/cjs/FieldArray/__stories__/Default/index.js +0 -128
- package/cjs/FieldArray/__stories__/Default.js.map +0 -7
- package/cjs/FieldArray/__stories__/WithExactLength/index.js +0 -128
- package/cjs/FieldArray/__stories__/WithExactLength.js.map +0 -7
- package/cjs/Form.stories/index.js +0 -26
- package/cjs/Form.stories.js.map +0 -7
- package/cjs/FormBuilder/FormBuilder.stories/index.js +0 -45
- package/cjs/FormBuilder/FormBuilder.stories.js.map +0 -7
- package/cjs/FormBuilder/__stories__/Default/index.js +0 -65
- package/cjs/FormBuilder/__stories__/Default.js.map +0 -7
- package/cjs/MultiplicityField/MultiplicityField.stories/index.js +0 -60
- package/cjs/MultiplicityField/MultiplicityField.stories.js.map +0 -7
- package/cjs/MultiplicityField/__stories__/Default/index.js +0 -133
- package/cjs/MultiplicityField/__stories__/Default.js.map +0 -7
- package/cjs/MultiplicityField/__stories__/PreviewDisplay/index.js +0 -86
- package/cjs/MultiplicityField/__stories__/PreviewDisplay.js.map +0 -7
- package/cjs/MultiplicityField/__stories__/WithExactLength/index.js +0 -130
- package/cjs/MultiplicityField/__stories__/WithExactLength.js.map +0 -7
- package/cjs/MultiplicityField/__stories__/WithMaxLength/index.js +0 -133
- package/cjs/MultiplicityField/__stories__/WithMaxLength.js.map +0 -7
- package/cjs/MultiplicityField/__stories__/WithMinAndMaxLength/index.js +0 -134
- package/cjs/MultiplicityField/__stories__/WithMinAndMaxLength.js.map +0 -7
- package/cjs/MultiplicityField/__stories__/WithMinLength/index.js +0 -133
- package/cjs/MultiplicityField/__stories__/WithMinLength.js.map +0 -7
- package/cjs/Questions/Questions.stories/index.js +0 -45
- package/cjs/Questions/Questions.stories.js.map +0 -7
- package/cjs/Questions/__stories__/Default/index.js +0 -136
- package/cjs/Questions/__stories__/Default.js.map +0 -7
- package/cjs/inputs/AutoCompleteInput/AutoComplete.stories/index.js +0 -48
- package/cjs/inputs/AutoCompleteInput/AutoComplete.stories.js.map +0 -7
- package/cjs/inputs/AutoCompleteInput/__stories__/Default/index.js +0 -83
- package/cjs/inputs/AutoCompleteInput/__stories__/Default.js.map +0 -7
- package/cjs/inputs/AutoCompleteInput/__stories__/Multiple/index.js +0 -83
- package/cjs/inputs/AutoCompleteInput/__stories__/Multiple.js.map +0 -7
- package/cjs/inputs/Checkboxes/Checkboxes.stories/index.js +0 -51
- package/cjs/inputs/Checkboxes/Checkboxes.stories.js.map +0 -7
- package/cjs/inputs/Checkboxes/__stories__/Conditional/index.js +0 -133
- package/cjs/inputs/Checkboxes/__stories__/Conditional.js.map +0 -7
- package/cjs/inputs/Checkboxes/__stories__/Default/index.js +0 -77
- package/cjs/inputs/Checkboxes/__stories__/Default.js.map +0 -7
- package/cjs/inputs/Checkboxes/__stories__/WithDivider/index.js +0 -78
- package/cjs/inputs/Checkboxes/__stories__/WithDivider.js.map +0 -7
- package/cjs/inputs/DateInput/DateInput.stories/index.js +0 -45
- package/cjs/inputs/DateInput/DateInput.stories.js.map +0 -7
- package/cjs/inputs/DateInput/__stories__/Default/index.js +0 -61
- package/cjs/inputs/DateInput/__stories__/Default.js.map +0 -7
- package/cjs/inputs/FileInput/FileInput.stories/index.js +0 -45
- package/cjs/inputs/FileInput/FileInput.stories.js.map +0 -7
- package/cjs/inputs/FileInput/__stories__/Default/index.js +0 -61
- package/cjs/inputs/FileInput/__stories__/Default.js.map +0 -7
- package/cjs/inputs/ImageInput/ImageInput.stories/index.js +0 -51
- package/cjs/inputs/ImageInput/ImageInput.stories.js.map +0 -7
- package/cjs/inputs/ImageInput/__stories__/Default/index.js +0 -63
- package/cjs/inputs/ImageInput/__stories__/Default.js.map +0 -7
- package/cjs/inputs/ImageInput/__stories__/MaxSize/index.js +0 -69
- package/cjs/inputs/ImageInput/__stories__/MaxSize.js.map +0 -7
- package/cjs/inputs/ImageInput/__stories__/WithInvalidImageDimension/index.js +0 -72
- package/cjs/inputs/ImageInput/__stories__/WithInvalidImageDimension.js.map +0 -7
- package/cjs/inputs/ImageInput/__stories__/WithInvalidImageSize/index.js +0 -68
- package/cjs/inputs/ImageInput/__stories__/WithInvalidImageSize.js.map +0 -7
- package/cjs/inputs/Input/Input.stories/index.js +0 -72
- package/cjs/inputs/Input/Input.stories.js.map +0 -7
- package/cjs/inputs/Input/__stories__/AFM/index.js +0 -63
- package/cjs/inputs/Input/__stories__/AFM.js.map +0 -7
- package/cjs/inputs/Input/__stories__/Boolean/index.js +0 -64
- package/cjs/inputs/Input/__stories__/Boolean.js.map +0 -7
- package/cjs/inputs/Input/__stories__/IBAN/index.js +0 -64
- package/cjs/inputs/Input/__stories__/IBAN.js.map +0 -7
- package/cjs/inputs/Input/__stories__/Integer/index.js +0 -78
- package/cjs/inputs/Input/__stories__/Integer.js.map +0 -7
- package/cjs/inputs/Input/__stories__/LandlineNumber/index.js +0 -68
- package/cjs/inputs/Input/__stories__/LandlineNumber.js.map +0 -7
- package/cjs/inputs/Input/__stories__/MobilePhone/index.js +0 -68
- package/cjs/inputs/Input/__stories__/MobilePhone.js.map +0 -7
- package/cjs/inputs/Input/__stories__/PhoneNumber/index.js +0 -67
- package/cjs/inputs/Input/__stories__/PhoneNumber.js.map +0 -7
- package/cjs/inputs/Input/__stories__/PostalCode/index.js +0 -65
- package/cjs/inputs/Input/__stories__/PostalCode.js.map +0 -7
- package/cjs/inputs/Input/__stories__/String/index.js +0 -64
- package/cjs/inputs/Input/__stories__/String.js.map +0 -7
- package/cjs/inputs/Input/__stories__/TextWithLimit/index.js +0 -64
- package/cjs/inputs/Input/__stories__/TextWithLimit.js.map +0 -7
- package/cjs/inputs/Input/inputsInputScenarios/index.js +0 -439
- package/cjs/inputs/Input/inputsInputScenarios.js.map +0 -7
- package/cjs/inputs/Label/Label.stories/index.js +0 -45
- package/cjs/inputs/Label/Label.stories.js.map +0 -7
- package/cjs/inputs/Label/__stories__/Default/index.js +0 -72
- package/cjs/inputs/Label/__stories__/Default.js.map +0 -7
- package/cjs/inputs/OtpInput/OtpInput.stories/index.js +0 -45
- package/cjs/inputs/OtpInput/OtpInput.stories.js.map +0 -7
- package/cjs/inputs/OtpInput/__stories__/Default/index.js +0 -64
- package/cjs/inputs/OtpInput/__stories__/Default.js.map +0 -7
- package/cjs/inputs/Radio/Radio.stories/index.js +0 -51
- package/cjs/inputs/Radio/Radio.stories.js.map +0 -7
- package/cjs/inputs/Radio/__stories__/Conditional/index.js +0 -133
- package/cjs/inputs/Radio/__stories__/Conditional.js.map +0 -7
- package/cjs/inputs/Radio/__stories__/Default/index.js +0 -81
- package/cjs/inputs/Radio/__stories__/Default.js.map +0 -7
- package/cjs/inputs/Radio/__stories__/WithDivider/index.js +0 -82
- package/cjs/inputs/Radio/__stories__/WithDivider.js.map +0 -7
- package/cjs/inputs/Select/Select.stories/index.js +0 -45
- package/cjs/inputs/Select/Select.stories.js.map +0 -7
- package/cjs/inputs/Select/__stories__/Default/index.js +0 -86
- package/cjs/inputs/Select/__stories__/Default.js.map +0 -7
- package/inputs/AutoCompleteInput/AutoComplete.stories/index.js +0 -14
- package/inputs/AutoCompleteInput/AutoComplete.stories/package.json +0 -6
- package/inputs/AutoCompleteInput/AutoComplete.stories.js.map +0 -7
- package/inputs/AutoCompleteInput/__stories__/Default/index.js +0 -50
- package/inputs/AutoCompleteInput/__stories__/Default/package.json +0 -6
- package/inputs/AutoCompleteInput/__stories__/Default.js.map +0 -7
- package/inputs/AutoCompleteInput/__stories__/Multiple/index.js +0 -50
- package/inputs/AutoCompleteInput/__stories__/Multiple/package.json +0 -6
- package/inputs/AutoCompleteInput/__stories__/Multiple.js.map +0 -7
- package/inputs/Checkboxes/Checkboxes.stories/index.js +0 -16
- package/inputs/Checkboxes/Checkboxes.stories/package.json +0 -6
- package/inputs/Checkboxes/Checkboxes.stories.js.map +0 -7
- package/inputs/Checkboxes/__stories__/Conditional/index.js +0 -100
- package/inputs/Checkboxes/__stories__/Conditional/package.json +0 -6
- package/inputs/Checkboxes/__stories__/Conditional.js.map +0 -7
- package/inputs/Checkboxes/__stories__/Default/index.js +0 -44
- package/inputs/Checkboxes/__stories__/Default/package.json +0 -6
- package/inputs/Checkboxes/__stories__/Default.js.map +0 -7
- package/inputs/Checkboxes/__stories__/WithDivider/index.js +0 -45
- package/inputs/Checkboxes/__stories__/WithDivider/package.json +0 -6
- package/inputs/Checkboxes/__stories__/WithDivider.js.map +0 -7
- package/inputs/DateInput/DateInput.stories/index.js +0 -12
- package/inputs/DateInput/DateInput.stories/package.json +0 -6
- package/inputs/DateInput/DateInput.stories.js.map +0 -7
- package/inputs/DateInput/__stories__/Default/index.js +0 -28
- package/inputs/DateInput/__stories__/Default.js.map +0 -7
- package/inputs/FileInput/FileInput.stories/index.js +0 -12
- package/inputs/FileInput/FileInput.stories/package.json +0 -6
- package/inputs/FileInput/FileInput.stories.js.map +0 -7
- package/inputs/FileInput/__stories__/Default/index.js +0 -28
- package/inputs/FileInput/__stories__/Default/package.json +0 -6
- package/inputs/FileInput/__stories__/Default.js.map +0 -7
- package/inputs/ImageInput/ImageInput.stories/index.js +0 -16
- package/inputs/ImageInput/ImageInput.stories/package.json +0 -6
- package/inputs/ImageInput/ImageInput.stories.js.map +0 -7
- package/inputs/ImageInput/__stories__/Default/index.js +0 -30
- package/inputs/ImageInput/__stories__/Default/package.json +0 -6
- package/inputs/ImageInput/__stories__/Default.js.map +0 -7
- package/inputs/ImageInput/__stories__/MaxSize/index.js +0 -36
- package/inputs/ImageInput/__stories__/MaxSize/package.json +0 -6
- package/inputs/ImageInput/__stories__/MaxSize.js.map +0 -7
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension/index.js +0 -39
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension/package.json +0 -6
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension.js.map +0 -7
- package/inputs/ImageInput/__stories__/WithInvalidImageSize/index.js +0 -35
- package/inputs/ImageInput/__stories__/WithInvalidImageSize/package.json +0 -6
- package/inputs/ImageInput/__stories__/WithInvalidImageSize.d.ts +0 -3
- package/inputs/ImageInput/__stories__/WithInvalidImageSize.js.map +0 -7
- package/inputs/Input/Input.stories/index.js +0 -30
- package/inputs/Input/Input.stories.js.map +0 -7
- package/inputs/Input/__stories__/AFM/index.js +0 -30
- package/inputs/Input/__stories__/AFM/package.json +0 -6
- package/inputs/Input/__stories__/AFM.js.map +0 -7
- package/inputs/Input/__stories__/Boolean/index.js +0 -31
- package/inputs/Input/__stories__/Boolean/package.json +0 -6
- package/inputs/Input/__stories__/Boolean.js.map +0 -7
- package/inputs/Input/__stories__/IBAN/index.js +0 -31
- package/inputs/Input/__stories__/IBAN/package.json +0 -6
- package/inputs/Input/__stories__/IBAN.js.map +0 -7
- package/inputs/Input/__stories__/Integer/index.js +0 -45
- package/inputs/Input/__stories__/Integer/package.json +0 -6
- package/inputs/Input/__stories__/Integer.js.map +0 -7
- package/inputs/Input/__stories__/LandlineNumber/index.js +0 -35
- package/inputs/Input/__stories__/LandlineNumber/package.json +0 -6
- package/inputs/Input/__stories__/LandlineNumber.js.map +0 -7
- package/inputs/Input/__stories__/MobilePhone/index.js +0 -35
- package/inputs/Input/__stories__/MobilePhone/package.json +0 -6
- package/inputs/Input/__stories__/MobilePhone.js.map +0 -7
- package/inputs/Input/__stories__/PhoneNumber/index.js +0 -34
- package/inputs/Input/__stories__/PhoneNumber/package.json +0 -6
- package/inputs/Input/__stories__/PhoneNumber.js.map +0 -7
- package/inputs/Input/__stories__/PostalCode/index.js +0 -32
- package/inputs/Input/__stories__/PostalCode/package.json +0 -6
- package/inputs/Input/__stories__/PostalCode.js.map +0 -7
- package/inputs/Input/__stories__/String/index.js +0 -31
- package/inputs/Input/__stories__/String/package.json +0 -6
- package/inputs/Input/__stories__/String.js.map +0 -7
- package/inputs/Input/__stories__/TextWithLimit/index.js +0 -31
- package/inputs/Input/__stories__/TextWithLimit/package.json +0 -6
- package/inputs/Input/__stories__/TextWithLimit.js.map +0 -7
- package/inputs/Input/inputsInputScenarios/index.js +0 -406
- package/inputs/Input/inputsInputScenarios/package.json +0 -6
- package/inputs/Input/inputsInputScenarios.d.ts +0 -57
- package/inputs/Input/inputsInputScenarios.js.map +0 -7
- package/inputs/Label/Label.stories/index.js +0 -12
- package/inputs/Label/Label.stories/package.json +0 -6
- package/inputs/Label/Label.stories.js.map +0 -7
- package/inputs/Label/__stories__/Default/index.js +0 -39
- package/inputs/Label/__stories__/Default/package.json +0 -6
- package/inputs/Label/__stories__/Default.js.map +0 -7
- package/inputs/OtpInput/OtpInput.stories/index.js +0 -12
- package/inputs/OtpInput/OtpInput.stories/package.json +0 -6
- package/inputs/OtpInput/OtpInput.stories.js.map +0 -7
- package/inputs/OtpInput/__stories__/Default/index.js +0 -31
- package/inputs/OtpInput/__stories__/Default/package.json +0 -6
- package/inputs/OtpInput/__stories__/Default.js.map +0 -7
- package/inputs/Radio/Radio.stories/index.js +0 -16
- package/inputs/Radio/Radio.stories/package.json +0 -6
- package/inputs/Radio/Radio.stories.js.map +0 -7
- package/inputs/Radio/__stories__/Conditional/index.js +0 -100
- package/inputs/Radio/__stories__/Conditional/package.json +0 -6
- package/inputs/Radio/__stories__/Conditional.js.map +0 -7
- package/inputs/Radio/__stories__/Default/index.js +0 -48
- package/inputs/Radio/__stories__/Default/package.json +0 -6
- package/inputs/Radio/__stories__/Default.js.map +0 -7
- package/inputs/Radio/__stories__/WithDivider/index.js +0 -49
- package/inputs/Radio/__stories__/WithDivider/package.json +0 -6
- package/inputs/Radio/__stories__/WithDivider.js.map +0 -7
- package/inputs/Select/Select.stories/index.js +0 -12
- package/inputs/Select/Select.stories/package.json +0 -6
- package/inputs/Select/Select.stories.js.map +0 -7
- package/inputs/Select/__stories__/Default/index.js +0 -53
- package/inputs/Select/__stories__/Default/package.json +0 -6
- package/inputs/Select/__stories__/Default.js.map +0 -7
- package/lazy.d.ts +0 -80
- package/lazy.js.map +0 -7
- package/registry.d.ts +0 -71
- package/registry.js.map +0 -7
- package/src/inputs/Input/inputsInputScenarios.ts +0 -405
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
3
|
+
import { FieldSpec } from '@digigov/form/types';
|
|
4
|
+
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
5
|
+
|
|
6
|
+
dayjs.extend(customParseFormat);
|
|
7
|
+
|
|
8
|
+
const VALID_DATETIME_FORMATS = ['DD/MM/YYYY HH:mm'];
|
|
9
|
+
const DATETIME_CACHE = {};
|
|
10
|
+
const onlyNumbersRegex = /^\d+$/;
|
|
11
|
+
|
|
12
|
+
const getDateTime = (v: string) => {
|
|
13
|
+
return DATETIME_CACHE[v]
|
|
14
|
+
? DATETIME_CACHE[v]
|
|
15
|
+
: dayjs(v, VALID_DATETIME_FORMATS, true);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const getDaysInMonth = (month: number, year: number): number => {
|
|
19
|
+
return dayjs(`${year}-${month}-01`).daysInMonth(); // e.g. 29 for Feb 2024
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const checkPartialDateTime = (value: string) => {
|
|
23
|
+
const [datePart, timePart] = value.split(' ');
|
|
24
|
+
const [day, month, year] = datePart?.split('/') ?? [];
|
|
25
|
+
const [hours, minutes] = timePart?.split(':') ?? [];
|
|
26
|
+
|
|
27
|
+
const hasDay = Boolean(day);
|
|
28
|
+
const hasMonth = Boolean(month);
|
|
29
|
+
const hasYear = Boolean(year);
|
|
30
|
+
const hasHours = Boolean(hours);
|
|
31
|
+
const hasMinutes = Boolean(minutes);
|
|
32
|
+
|
|
33
|
+
if (hasDay && !hasMonth && !hasYear && !hasHours && !hasMinutes) {
|
|
34
|
+
return 'form.error.datetime.invalid_month_year_hours_minutes';
|
|
35
|
+
}
|
|
36
|
+
if (!hasDay && hasMonth && !hasYear && !hasHours && !hasMinutes) {
|
|
37
|
+
return 'form.error.datetime.invalid_day_year_hours_minutes';
|
|
38
|
+
}
|
|
39
|
+
if (!hasDay && !hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
40
|
+
return 'form.error.datetime.invalid_day_month_hours_minutes';
|
|
41
|
+
}
|
|
42
|
+
if (hasDay && hasMonth && !hasYear && !hasHours && !hasMinutes) {
|
|
43
|
+
return 'form.error.datetime.invalid_year_hours_minutes';
|
|
44
|
+
}
|
|
45
|
+
if (hasDay && !hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
46
|
+
return 'form.error.datetime.invalid_month_hours_minutes';
|
|
47
|
+
}
|
|
48
|
+
if (!hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
49
|
+
return 'form.error.datetime.invalid_day_hours_minutes';
|
|
50
|
+
}
|
|
51
|
+
if (hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
52
|
+
return 'form.error.datetime.invalid__hours_minutes';
|
|
53
|
+
}
|
|
54
|
+
if (hasDay && hasMonth && hasYear && hasHours && !hasMinutes) {
|
|
55
|
+
return 'form.error.datetime.invalid_minutes';
|
|
56
|
+
}
|
|
57
|
+
if (hasDay && hasMonth && hasYear && !hasHours && hasMinutes) {
|
|
58
|
+
return 'form.error.datetime.invalid_hours';
|
|
59
|
+
}
|
|
60
|
+
if (hasDay && !hasMonth && !hasYear && hasHours && !hasMinutes) {
|
|
61
|
+
return 'form.error.datetime.invalid_month_year_minutes';
|
|
62
|
+
}
|
|
63
|
+
if (hasDay && !hasMonth && !hasYear && !hasHours && hasMinutes) {
|
|
64
|
+
return 'form.error.datetime.invalid_month_year_hours';
|
|
65
|
+
}
|
|
66
|
+
if (hasDay && !hasMonth && !hasYear && hasHours && hasMinutes) {
|
|
67
|
+
return 'form.error.datetime.invalid_month_year';
|
|
68
|
+
}
|
|
69
|
+
if (!hasDay && hasMonth && !hasYear && hasHours && !hasMinutes) {
|
|
70
|
+
return 'form.error.datetime.invalid_day_year_minutes';
|
|
71
|
+
}
|
|
72
|
+
if (!hasDay && hasMonth && !hasYear && !hasHours && hasMinutes) {
|
|
73
|
+
return 'form.error.datetime.invalid_day_year_hours';
|
|
74
|
+
}
|
|
75
|
+
if (!hasDay && hasMonth && !hasYear && hasHours && hasMinutes) {
|
|
76
|
+
return 'form.error.datetime.invalid_day_year';
|
|
77
|
+
}
|
|
78
|
+
if (!hasDay && !hasMonth && hasYear && hasHours && !hasMinutes) {
|
|
79
|
+
return 'form.error.datetime.invalid_day_month_minutes';
|
|
80
|
+
}
|
|
81
|
+
if (!hasDay && !hasMonth && hasYear && !hasHours && hasMinutes) {
|
|
82
|
+
return 'form.error.datetime.invalid_day_month_hours';
|
|
83
|
+
}
|
|
84
|
+
if (!hasDay && !hasMonth && hasYear && hasHours && hasMinutes) {
|
|
85
|
+
return 'form.error.datetime.invalid_day_month';
|
|
86
|
+
}
|
|
87
|
+
if (!hasDay && !hasMonth && !hasYear && hasHours && hasMinutes) {
|
|
88
|
+
return 'form.error.datetime.invalid_day_month_year';
|
|
89
|
+
}
|
|
90
|
+
if (!hasDay && !hasMonth && !hasYear && !hasHours && hasMinutes) {
|
|
91
|
+
return 'form.error.datetime.invalid_day_month_year_hours';
|
|
92
|
+
}
|
|
93
|
+
if (hasDay && hasMonth && !hasYear && hasHours && !hasMinutes) {
|
|
94
|
+
return 'form.error.datetime.invalid_year_minutes';
|
|
95
|
+
}
|
|
96
|
+
if (hasDay && hasMonth && !hasYear && !hasHours && hasMinutes) {
|
|
97
|
+
return 'form.error.datetime.invalid_year_hours';
|
|
98
|
+
}
|
|
99
|
+
if (
|
|
100
|
+
hasDay &&
|
|
101
|
+
hasMonth &&
|
|
102
|
+
(!hasYear || year.length < 4) &&
|
|
103
|
+
hasHours &&
|
|
104
|
+
hasMinutes
|
|
105
|
+
) {
|
|
106
|
+
return 'form.error.datetime.invalid_year';
|
|
107
|
+
}
|
|
108
|
+
if (hasDay && !hasMonth && hasYear && hasHours && !hasMinutes) {
|
|
109
|
+
return 'form.error.datetime.invalid_month_minutes';
|
|
110
|
+
}
|
|
111
|
+
if (hasDay && !hasMonth && hasYear && !hasHours && hasMinutes) {
|
|
112
|
+
return 'form.error.datetime.invalid_month_hours';
|
|
113
|
+
}
|
|
114
|
+
if (hasDay && !hasMonth && hasYear && hasHours && hasMinutes) {
|
|
115
|
+
return 'form.error.datetime.invalid_month';
|
|
116
|
+
}
|
|
117
|
+
if (!hasDay && hasMonth && hasYear && hasHours && !hasMinutes) {
|
|
118
|
+
return 'form.error.datetime.invalid_day_minutes';
|
|
119
|
+
}
|
|
120
|
+
if (!hasDay && hasMonth && hasYear && !hasHours && hasMinutes) {
|
|
121
|
+
return 'form.error.datetime.invalid_day_hours';
|
|
122
|
+
}
|
|
123
|
+
if (!hasDay && hasMonth && hasYear && hasHours && hasMinutes) {
|
|
124
|
+
return 'form.error.datetime.invalid_day';
|
|
125
|
+
}
|
|
126
|
+
if (!hasDay && !hasMonth && !hasYear && hasHours && !hasMinutes) {
|
|
127
|
+
return 'form.error.datetime.invalid_day_month_year_minutes';
|
|
128
|
+
}
|
|
129
|
+
if (hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
130
|
+
return 'form.error.datetime.invalid_hours_minutes';
|
|
131
|
+
}
|
|
132
|
+
if (day && month) {
|
|
133
|
+
const dayNum = parseInt(day);
|
|
134
|
+
const monthNum = parseInt(month);
|
|
135
|
+
const validYear = onlyNumbersRegex.test(year) ? year : undefined;
|
|
136
|
+
if (!validYear) {
|
|
137
|
+
return 'form.error.datetime.invalid';
|
|
138
|
+
}
|
|
139
|
+
const yearNum = parseInt(validYear);
|
|
140
|
+
const maxDay = getDaysInMonth(monthNum, yearNum);
|
|
141
|
+
if (dayNum < 1 || dayNum > maxDay) {
|
|
142
|
+
return {
|
|
143
|
+
key: 'form.error.datetime.invalid_day_range',
|
|
144
|
+
context: {
|
|
145
|
+
maxDay: maxDay,
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
if (monthNum < 1 || monthNum > 12) {
|
|
150
|
+
return 'form.error.datetime.invalid_month_range';
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (hours && minutes) {
|
|
154
|
+
const hoursNum = parseInt(hours);
|
|
155
|
+
const minutesNum = parseInt(minutes);
|
|
156
|
+
if (hoursNum < 0 || hoursNum > 23) {
|
|
157
|
+
return 'form.error.datetime.invalid_hours_range';
|
|
158
|
+
}
|
|
159
|
+
if (minutesNum < 0 || minutesNum > 59) {
|
|
160
|
+
return 'form.error.datetime.invalid_minutes_range';
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return 'form.error.datetime.invalid';
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
export const LATER_THAN_DATETIME_VALIDATOR = (
|
|
167
|
+
field: FieldSpec
|
|
168
|
+
): ValidatorSchema => {
|
|
169
|
+
let minDateTime;
|
|
170
|
+
const params = field.extra || {};
|
|
171
|
+
if (params.min === 'now') {
|
|
172
|
+
minDateTime = dayjs();
|
|
173
|
+
} else {
|
|
174
|
+
minDateTime = getDateTime(params.min);
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
name: 'later-than-datetime',
|
|
178
|
+
message: {
|
|
179
|
+
key: 'form.error.datetime.later_than',
|
|
180
|
+
context: {
|
|
181
|
+
minDateTime: minDateTime.format('DD/MM/YYYY HH:mm'),
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
test: function (value: string) {
|
|
185
|
+
if (!value) return true;
|
|
186
|
+
const datetime = getDateTime(value);
|
|
187
|
+
return datetime.isValid() && datetime.isAfter(minDateTime);
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
export const EARLIER_THAN_DATETIME_VALIDATOR = (
|
|
193
|
+
field: FieldSpec
|
|
194
|
+
): ValidatorSchema => {
|
|
195
|
+
let maxDateTime;
|
|
196
|
+
const params = field.extra || {};
|
|
197
|
+
if (params.max === 'now') {
|
|
198
|
+
maxDateTime = dayjs();
|
|
199
|
+
} else {
|
|
200
|
+
maxDateTime = getDateTime(params.max);
|
|
201
|
+
}
|
|
202
|
+
return {
|
|
203
|
+
name: 'earlier-than-datetime',
|
|
204
|
+
message: {
|
|
205
|
+
key: 'form.error.datetime.earlier_than',
|
|
206
|
+
context: {
|
|
207
|
+
maxDateTime: maxDateTime.format('DD/MM/YYYY HH:mm'),
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
test: function (value: string) {
|
|
211
|
+
if (!value) return true;
|
|
212
|
+
const datetime = getDateTime(value);
|
|
213
|
+
return datetime.isValid() && datetime.isBefore(maxDateTime);
|
|
214
|
+
},
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
export const DATETIME_VALIDATOR = {
|
|
219
|
+
name: 'datetime-validator',
|
|
220
|
+
message: (v): string | object => {
|
|
221
|
+
return checkPartialDateTime(v.value);
|
|
222
|
+
},
|
|
223
|
+
test: function (value: string) {
|
|
224
|
+
if (!value) return true;
|
|
225
|
+
const datetime = getDateTime(value);
|
|
226
|
+
return datetime.isValid();
|
|
227
|
+
},
|
|
228
|
+
};
|
|
@@ -3,23 +3,39 @@ import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
|
3
3
|
|
|
4
4
|
const DEFAULT_FILE_MAX_SIZE = 10000000;
|
|
5
5
|
|
|
6
|
-
export const FILE_MAX_SIZE_VALIDATOR = (field: FieldSpec): ValidatorSchema =>
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
export const FILE_MAX_SIZE_VALIDATOR = (field: FieldSpec): ValidatorSchema => {
|
|
7
|
+
const maxSizeInBytes = field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE;
|
|
8
|
+
let maxSizeTransformed = maxSizeInBytes / (1024 * 1024); // In MB
|
|
9
|
+
let maxSizeText = 'MB';
|
|
10
|
+
if (Math.round(maxSizeTransformed) === 0) {
|
|
11
|
+
maxSizeTransformed = Math.round(maxSizeInBytes / 1024);
|
|
12
|
+
maxSizeText = 'KB';
|
|
13
|
+
}
|
|
14
|
+
if (Math.round(maxSizeTransformed) === 0) {
|
|
15
|
+
maxSizeTransformed = maxSizeInBytes;
|
|
16
|
+
maxSizeText = 'Bytes';
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
name: 'file-max-size-validator',
|
|
20
|
+
message: {
|
|
21
|
+
key:
|
|
22
|
+
field.type === 'file'
|
|
23
|
+
? 'form.error.file_size'
|
|
24
|
+
: 'form.error.image_size',
|
|
25
|
+
context: {
|
|
26
|
+
maxSize: `${maxSizeTransformed} ${maxSizeText}`,
|
|
27
|
+
},
|
|
12
28
|
},
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
29
|
+
test: (value: File[]): boolean => {
|
|
30
|
+
if (value) {
|
|
31
|
+
for (const file of Array.from(value)) {
|
|
32
|
+
const maxSize = field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE;
|
|
33
|
+
if (file.size > maxSize) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
20
36
|
}
|
|
21
37
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
}
|
|
38
|
+
return true;
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
};
|
|
@@ -3,6 +3,7 @@ import { FieldSpec } from '@digigov/form/types';
|
|
|
3
3
|
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
4
4
|
|
|
5
5
|
export * from '@digigov/form/validators/utils/afm';
|
|
6
|
+
export * from '@digigov/form/validators/utils/amka';
|
|
6
7
|
export * from '@digigov/form/validators/utils/file';
|
|
7
8
|
export * from '@digigov/form/validators/utils/iban';
|
|
8
9
|
export * from '@digigov/form/validators/utils/otp';
|
|
@@ -12,6 +13,7 @@ export * from '@digigov/form/validators/utils/postal_code';
|
|
|
12
13
|
export * from '@digigov/form/validators/utils/uuid4';
|
|
13
14
|
export * from '@digigov/form/validators/utils/text_limit';
|
|
14
15
|
export * from '@digigov/form/validators/utils/date';
|
|
16
|
+
export * from '@digigov/form/validators/utils/datetime';
|
|
15
17
|
|
|
16
18
|
export function getYupField(field: FieldSpec, yupTypeMap: Record<string, any>) {
|
|
17
19
|
const yupField = yupTypeMap[field?.type || 'string'] || yupTypeMap['string'];
|
|
@@ -97,7 +99,9 @@ export function getYupObjectShape(
|
|
|
97
99
|
|
|
98
100
|
return yup.lazy(function () {
|
|
99
101
|
const fieldSchemas = computeShape(
|
|
100
|
-
Object.values(fields.current)
|
|
102
|
+
Object.values(fields.current).filter(
|
|
103
|
+
(f: FieldSpec) => !f.key.includes('.')
|
|
104
|
+
) as FieldSpec[],
|
|
101
105
|
yupTypeMap,
|
|
102
106
|
validatorRegistry
|
|
103
107
|
);
|
|
@@ -13,7 +13,7 @@ export const INT_VALIDATOR = (): ValidatorSchema => {
|
|
|
13
13
|
name: 'int-validator',
|
|
14
14
|
message: 'form.error.positive_integer_number',
|
|
15
15
|
test: (value: number): boolean => {
|
|
16
|
-
if (value ===
|
|
16
|
+
if (value === undefined) {
|
|
17
17
|
return true;
|
|
18
18
|
}
|
|
19
19
|
return validateIntNumber(value);
|
|
@@ -9,7 +9,7 @@ export const NUMBER_VALIDATOR = (): ValidatorSchema => {
|
|
|
9
9
|
name: 'number-validator',
|
|
10
10
|
message: 'form.error.number',
|
|
11
11
|
test: (value: number): boolean => {
|
|
12
|
-
if (value ===
|
|
12
|
+
if (value === undefined) {
|
|
13
13
|
return true;
|
|
14
14
|
}
|
|
15
15
|
return validateNumber(value);
|
|
@@ -138,7 +138,7 @@ function isNumberOfType(phoneNumber: string, country: string, type: string) {
|
|
|
138
138
|
}
|
|
139
139
|
export function validatePhoneNumber(
|
|
140
140
|
phoneNumber: string,
|
|
141
|
-
countries:
|
|
141
|
+
countries: string[] = ['gr'],
|
|
142
142
|
typeOfPhoneNumber?: PhoneNumberType
|
|
143
143
|
): boolean {
|
|
144
144
|
if (!countries || countries.length === 0) {
|
|
@@ -4,7 +4,7 @@ import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
|
4
4
|
const CODE_REGEX = /^[12345678][0-9]{4}$/;
|
|
5
5
|
export function validatePostalCode(
|
|
6
6
|
number: string,
|
|
7
|
-
countries:
|
|
7
|
+
countries: string[]
|
|
8
8
|
): boolean {
|
|
9
9
|
if (!countries) {
|
|
10
10
|
return false;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
const UUID4_PATTERN =
|
|
1
|
+
const UUID4_PATTERN =
|
|
2
|
+
/^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i;
|
|
2
3
|
|
|
3
4
|
export function validateUUID4(uuid4: string): boolean {
|
|
4
5
|
if (uuid4.length !== 36) {
|
|
@@ -75,14 +75,14 @@ it('throws if given country is not supported', () => {
|
|
|
75
75
|
);
|
|
76
76
|
});
|
|
77
77
|
|
|
78
|
-
it('validates
|
|
78
|
+
it('validates phone number type mobile with gr country code', () => {
|
|
79
79
|
expect(validatePhoneNumber('6934100982', ['GR'], 'mobile')).toBe(true);
|
|
80
80
|
});
|
|
81
81
|
|
|
82
|
-
it('validates
|
|
82
|
+
it('validates phone number with no type and gr country code', () => {
|
|
83
83
|
expect(validatePhoneNumber('6934100982', ['gr'], null)).toBe(true);
|
|
84
84
|
});
|
|
85
85
|
|
|
86
|
-
it('validates
|
|
86
|
+
it('validates invalid phone number with no type and gr country code', () => {
|
|
87
87
|
expect(validatePhoneNumber('41446681800', ['gr'], null)).toBe(false);
|
|
88
88
|
});
|
package/types.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { UseFormReturn, UseFormProps } from 'react-hook-form';
|
|
1
|
+
import { UseFormReturn, UseFormProps, ErrorOption } from 'react-hook-form';
|
|
2
2
|
import { FieldComponentRegistry, FieldLabelProps, FieldSpec, FormData } from '@digigov/form/Field/types';
|
|
3
3
|
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
4
4
|
export * from '@digigov/form/Field/types';
|
|
5
|
-
export
|
|
5
|
+
export interface FieldError {
|
|
6
6
|
message: string;
|
|
7
|
-
}
|
|
7
|
+
}
|
|
8
8
|
export interface FieldsetSpec {
|
|
9
9
|
key: string;
|
|
10
10
|
fields: string[];
|
|
@@ -46,6 +46,7 @@ export interface FormBuilderProps {
|
|
|
46
46
|
componentRegistry?: FieldComponentRegistry;
|
|
47
47
|
grid?: boolean;
|
|
48
48
|
controlledFieldsOnly?: boolean;
|
|
49
|
+
errors?: ErrorOption;
|
|
49
50
|
}
|
|
50
51
|
export interface FormBaseProps extends Omit<FormBuilderProps, 'fields' | 'fieldsets' | 'auto'> {
|
|
51
52
|
fieldsetsMap?: Record<string, FieldsetSpec>;
|
package/types.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/types.tsx"],
|
|
4
|
-
"sourcesContent": ["import { UseFormReturn, UseFormProps } from 'react-hook-form';\nimport {\n FieldComponentRegistry,\n FieldLabelProps,\n FieldSpec,\n FormData,\n} from '@digigov/form/Field/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\nexport * from '@digigov/form/Field/types';\nexport
|
|
4
|
+
"sourcesContent": ["import { UseFormReturn, UseFormProps, ErrorOption } from 'react-hook-form';\nimport {\n FieldComponentRegistry,\n FieldLabelProps,\n FieldSpec,\n FormData,\n} from '@digigov/form/Field/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\nexport * from '@digigov/form/Field/types';\nexport interface FieldError {\n message: string;\n}\n\nexport interface FieldsetSpec {\n key: string;\n fields: string[];\n label?: FieldLabelProps;\n body?: React.ReactNode;\n}\n\nexport interface FormContextProps {\n fieldsetsMap?: Record<string, FieldsetSpec>;\n fieldsMap: Record<string, FieldSpec>;\n control: UseFormReturn['control'];\n register: UseFormReturn['register'];\n trigger: UseFormReturn['trigger'];\n clearErrors: UseFormReturn['clearErrors'];\n watch: UseFormReturn['watch'];\n getFieldState: UseFormReturn['getFieldState'];\n setValue: UseFormReturn['setValue'];\n getValues: UseFormReturn['getValues'];\n unregister: UseFormReturn['unregister'];\n formState: UseFormReturn['formState'];\n reset: UseFormReturn['reset'];\n resetField: UseFormReturn['resetField'];\n registerField: (field: FieldSpec) => void;\n errors: UseFormReturn['formState']['errors'];\n componentRegistry?: FieldComponentRegistry;\n submit: () => Promise<void>;\n}\n\nexport interface FormBuilderProps {\n fields?: FieldSpec[];\n fieldsets?: FieldsetSpec[];\n initial?: FormData;\n onSubmit?: (data: FormData) => void | null | FieldError[];\n mode?: UseFormProps['mode'];\n reValidateMode?: UseFormProps['reValidateMode'];\n criteriaMode?: UseFormProps['criteriaMode'];\n children?: React.ReactNode;\n shouldFocusError?: boolean;\n auto?: boolean;\n validatorRegistry?: Record<string, ValidatorSchema[]>;\n componentRegistry?: FieldComponentRegistry;\n grid?: boolean;\n controlledFieldsOnly?: boolean;\n errors?: ErrorOption;\n}\n\nexport interface FormBaseProps\n extends Omit<FormBuilderProps, 'fields' | 'fieldsets' | 'auto'> {\n fieldsetsMap?: Record<string, FieldsetSpec>;\n fieldsMap: Record<string, FieldSpec>;\n registerField: (field: FieldSpec) => void;\n resolver: any;\n}\n"],
|
|
5
5
|
"mappings": "AAQA,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/utils/index.js
CHANGED
|
@@ -23,6 +23,20 @@ const parseErrorSchema = (error, validateAllFieldCriteria) => {
|
|
|
23
23
|
{}
|
|
24
24
|
);
|
|
25
25
|
};
|
|
26
|
+
function isPlainObject(obj) {
|
|
27
|
+
return typeof obj === "object" && obj !== null && Object.prototype.toString.call(obj) === "[object Object]";
|
|
28
|
+
}
|
|
29
|
+
function flattenObject(obj, prefix = "") {
|
|
30
|
+
return Object.keys(obj).reduce((acc, key) => {
|
|
31
|
+
const prefixedKey = prefix ? `${prefix}.${key}` : key;
|
|
32
|
+
if (isPlainObject(obj[key])) {
|
|
33
|
+
Object.assign(acc, flattenObject(obj[key], prefixedKey));
|
|
34
|
+
} else {
|
|
35
|
+
acc[prefixedKey] = obj[key];
|
|
36
|
+
}
|
|
37
|
+
return acc;
|
|
38
|
+
}, {});
|
|
39
|
+
}
|
|
26
40
|
const yupResolver = (schema, schemaOptions = {}, resolverOptions = {}) => async (values, context, options) => {
|
|
27
41
|
try {
|
|
28
42
|
if (schemaOptions.context && process.env.NODE_ENV === "development") {
|
|
@@ -31,10 +45,11 @@ const yupResolver = (schema, schemaOptions = {}, resolverOptions = {}) => async
|
|
|
31
45
|
);
|
|
32
46
|
}
|
|
33
47
|
const result = await schema[resolverOptions.mode === "sync" ? "validateSync" : "validate"](
|
|
34
|
-
values,
|
|
48
|
+
flattenObject(values),
|
|
35
49
|
Object.assign({ abortEarly: false }, schemaOptions, { context })
|
|
36
50
|
);
|
|
37
|
-
options.shouldUseNativeValidation
|
|
51
|
+
if (options.shouldUseNativeValidation)
|
|
52
|
+
validateFieldsNatively({}, options);
|
|
38
53
|
return {
|
|
39
54
|
values: resolverOptions.rawValues ? values : result,
|
|
40
55
|
errors: {}
|
|
@@ -43,13 +58,13 @@ const yupResolver = (schema, schemaOptions = {}, resolverOptions = {}) => async
|
|
|
43
58
|
if (!e.inner) {
|
|
44
59
|
throw e;
|
|
45
60
|
}
|
|
46
|
-
const parsed = parseErrorSchema(
|
|
47
|
-
e,
|
|
48
|
-
!options.shouldUseNativeValidation && options.criteriaMode === "all"
|
|
49
|
-
);
|
|
50
61
|
return {
|
|
51
62
|
values: {},
|
|
52
|
-
errors:
|
|
63
|
+
errors: parseErrorSchema(
|
|
64
|
+
e,
|
|
65
|
+
!options.shouldUseNativeValidation && options.criteriaMode === "all"
|
|
66
|
+
),
|
|
67
|
+
options
|
|
53
68
|
};
|
|
54
69
|
}
|
|
55
70
|
};
|
package/utils.d.ts
CHANGED
|
@@ -2,7 +2,9 @@ import { FieldError } from 'react-hook-form';
|
|
|
2
2
|
export declare const yupResolver: (schema: any, schemaOptions?: any, resolverOptions?: any) => (values: any, context: any, options: any) => Promise<{
|
|
3
3
|
values: any;
|
|
4
4
|
errors: {};
|
|
5
|
+
options?: undefined;
|
|
5
6
|
} | {
|
|
6
7
|
values: {};
|
|
7
8
|
errors: Record<string, FieldError>;
|
|
9
|
+
options: any;
|
|
8
10
|
}>;
|
package/utils.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/utils.ts"],
|
|
4
|
-
"sourcesContent": ["import { validateFieldsNatively } from '@hookform/resolvers';\nimport { appendErrors, FieldError } from 'react-hook-form';\nimport * as Yup from 'yup';\n\n/**\n * Why `path!` ? because it could be `undefined` in some case\n * https://github.com/jquense/yup#validationerrorerrors-string--arraystring-value-any-path-string\n */\nconst parseErrorSchema = (\n error: Yup.ValidationError,\n validateAllFieldCriteria: boolean\n) => {\n return (error.inner || []).reduce<Record<string, FieldError>>(\n (previous, error) => {\n error.path = error.path?.replace(/\\[([0-9]+)\\]/g, '.$1');\n if (!previous[error.path!]) {\n previous[error.path!] = { message: error.message, type: error.type! };\n }\n\n if (validateAllFieldCriteria) {\n const types = previous[error.path!].types;\n const messages = types && types[error.type!];\n\n previous[error.path!] = appendErrors(\n error.path!,\n validateAllFieldCriteria,\n previous,\n error.type!,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message\n ) as FieldError;\n }\n\n return previous;\n },\n {}\n );\n};\n\nexport const yupResolver =\n (schema: any, schemaOptions: any = {}, resolverOptions: any = {}) =>\n async (values, context, options) => {\n try {\n if (schemaOptions.context && process.env.NODE_ENV === 'development') {\n
|
|
5
|
-
"mappings": "AAAA,SAAS,8BAA8B;AACvC,SAAS,oBAAgC;AAOzC,MAAM,mBAAmB,CACvB,OACA,6BACG;AACH,UAAQ,MAAM,SAAS,CAAC,GAAG;AAAA,IACzB,CAAC,UAAUA,WAAU;AACnB,MAAAA,OAAM,OAAOA,OAAM,MAAM,QAAQ,iBAAiB,KAAK;
|
|
4
|
+
"sourcesContent": ["import { validateFieldsNatively } from '@hookform/resolvers';\nimport { appendErrors, FieldError } from 'react-hook-form';\nimport * as Yup from 'yup';\n\n/**\n * Why `path!` ? because it could be `undefined` in some case\n * https://github.com/jquense/yup#validationerrorerrors-string--arraystring-value-any-path-string\n */\nconst parseErrorSchema = (\n error: Yup.ValidationError,\n validateAllFieldCriteria: boolean\n) => {\n return (error.inner || []).reduce<Record<string, FieldError>>(\n (previous, error) => {\n error.path = error.path?.replace(/\\[([0-9]+)\\]/g, '.$1');\n // error.path = error.path?.replace(/\\[\"(.*?)\"\\]/g, '$1');\n if (!previous[error.path!]) {\n previous[error.path!] = { message: error.message, type: error.type! };\n }\n\n if (validateAllFieldCriteria) {\n const types = previous[error.path!].types;\n const messages = types && types[error.type!];\n\n previous[error.path!] = appendErrors(\n error.path!,\n validateAllFieldCriteria,\n previous,\n error.type!,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message\n ) as FieldError;\n }\n\n return previous;\n },\n {}\n );\n};\nfunction isPlainObject(obj) {\n return (\n typeof obj === 'object' &&\n obj !== null &&\n Object.prototype.toString.call(obj) === '[object Object]'\n );\n}\nfunction flattenObject(obj, prefix = '') {\n return Object.keys(obj).reduce((acc, key) => {\n const prefixedKey = prefix ? `${prefix}.${key}` : key;\n\n if (isPlainObject(obj[key])) {\n Object.assign(acc, flattenObject(obj[key], prefixedKey));\n } else {\n acc[prefixedKey] = obj[key];\n }\n\n return acc;\n }, {});\n}\n\nexport const yupResolver =\n (schema: any, schemaOptions: any = {}, resolverOptions: any = {}) =>\n async (values, context, options) => {\n try {\n if (schemaOptions.context && process.env.NODE_ENV === 'development') {\n console.warn(\n \"You should not used the yup options context. Please, use the 'useForm' context object instead\"\n );\n }\n\n const result = await schema[\n resolverOptions.mode === 'sync' ? 'validateSync' : 'validate'\n ](\n flattenObject(values),\n Object.assign({ abortEarly: false }, schemaOptions, { context })\n );\n\n if (options.shouldUseNativeValidation)\n validateFieldsNatively({}, options);\n\n return {\n values: resolverOptions.rawValues ? values : result,\n errors: {},\n };\n } catch (e) {\n if (!e.inner) {\n throw e;\n }\n\n return {\n values: {},\n errors: parseErrorSchema(\n e,\n !options.shouldUseNativeValidation && options.criteriaMode === 'all'\n ),\n options,\n };\n }\n };\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,8BAA8B;AACvC,SAAS,oBAAgC;AAOzC,MAAM,mBAAmB,CACvB,OACA,6BACG;AACH,UAAQ,MAAM,SAAS,CAAC,GAAG;AAAA,IACzB,CAAC,UAAUA,WAAU;AACnB,MAAAA,OAAM,OAAOA,OAAM,MAAM,QAAQ,iBAAiB,KAAK;AAEvD,UAAI,CAAC,SAASA,OAAM,IAAK,GAAG;AAC1B,iBAASA,OAAM,IAAK,IAAI,EAAE,SAASA,OAAM,SAAS,MAAMA,OAAM,KAAM;AAAA,MACtE;AAEA,UAAI,0BAA0B;AAC5B,cAAM,QAAQ,SAASA,OAAM,IAAK,EAAE;AACpC,cAAM,WAAW,SAAS,MAAMA,OAAM,IAAK;AAE3C,iBAASA,OAAM,IAAK,IAAI;AAAA,UACtBA,OAAM;AAAA,UACN;AAAA,UACA;AAAA,UACAA,OAAM;AAAA,UACN,WACK,CAAC,EAAe,OAAO,UAAsBA,OAAM,OAAO,IAC3DA,OAAM;AAAA,QACZ;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AACF;AACA,SAAS,cAAc,KAAK;AAC1B,SACE,OAAO,QAAQ,YACf,QAAQ,QACR,OAAO,UAAU,SAAS,KAAK,GAAG,MAAM;AAE5C;AACA,SAAS,cAAc,KAAK,SAAS,IAAI;AACvC,SAAO,OAAO,KAAK,GAAG,EAAE,OAAO,CAAC,KAAK,QAAQ;AAC3C,UAAM,cAAc,SAAS,GAAG,MAAM,IAAI,GAAG,KAAK;AAElD,QAAI,cAAc,IAAI,GAAG,CAAC,GAAG;AAC3B,aAAO,OAAO,KAAK,cAAc,IAAI,GAAG,GAAG,WAAW,CAAC;AAAA,IACzD,OAAO;AACL,UAAI,WAAW,IAAI,IAAI,GAAG;AAAA,IAC5B;AAEA,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AACP;AAEO,MAAM,cACX,CAAC,QAAa,gBAAqB,CAAC,GAAG,kBAAuB,CAAC,MAC/D,OAAO,QAAQ,SAAS,YAAY;AAClC,MAAI;AACF,QAAI,cAAc,WAAW,QAAQ,IAAI,aAAa,eAAe;AACnE,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAEA,UAAM,SAAS,MAAM,OACnB,gBAAgB,SAAS,SAAS,iBAAiB,UACrD;AAAA,MACE,cAAc,MAAM;AAAA,MACpB,OAAO,OAAO,EAAE,YAAY,MAAM,GAAG,eAAe,EAAE,QAAQ,CAAC;AAAA,IACjE;AAEA,QAAI,QAAQ;AACV,6BAAuB,CAAC,GAAG,OAAO;AAEpC,WAAO;AAAA,MACL,QAAQ,gBAAgB,YAAY,SAAS;AAAA,MAC7C,QAAQ,CAAC;AAAA,IACX;AAAA,EACF,SAAS,GAAG;AACV,QAAI,CAAC,EAAE,OAAO;AACZ,YAAM;AAAA,IACR;AAEA,WAAO;AAAA,MACL,QAAQ,CAAC;AAAA,MACT,QAAQ;AAAA,QACN;AAAA,QACA,CAAC,QAAQ,6BAA6B,QAAQ,iBAAiB;AAAA,MACjE;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["error"]
|
|
7
7
|
}
|
package/validators/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { AnyObjectSchema } from 'yup';
|
|
|
3
3
|
import Lazy from 'yup/lib/Lazy';
|
|
4
4
|
import { FieldSpec } from '@digigov/form/types';
|
|
5
5
|
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
6
|
-
export declare const getYUPTypeMap: () => Record<string, any>;
|
|
6
|
+
export declare const getYUPTypeMap: (validatorRegistry?: Record<string, any>) => Record<string, any>;
|
|
7
7
|
export interface MutableRefObjectProps {
|
|
8
8
|
}
|
|
9
9
|
export declare function useValidationSchema(fields: FieldSpec[] | MutableRefObject<MutableRefObjectProps>, validatorRegistry?: Record<string, ValidatorSchema[]>): Lazy<any, unknown> | AnyObjectSchema | void;
|
package/validators/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import * as yup from "yup";
|
|
|
3
3
|
import {
|
|
4
4
|
getYupObjectShape,
|
|
5
5
|
AFM_VALIDATOR,
|
|
6
|
+
AMKA_VALIDATOR,
|
|
6
7
|
FILE_MAX_SIZE_VALIDATOR,
|
|
7
8
|
IBAN_VALIDATOR,
|
|
8
9
|
OTP_VALIDATOR,
|
|
@@ -14,21 +15,30 @@ import {
|
|
|
14
15
|
IMAGE_DIMENSION_VALIDATOR,
|
|
15
16
|
DATE_VALIDATOR,
|
|
16
17
|
LATER_THAN_VALIDATOR,
|
|
17
|
-
EARLIER_THAN_VALIDATOR
|
|
18
|
+
EARLIER_THAN_VALIDATOR,
|
|
19
|
+
DATETIME_VALIDATOR,
|
|
20
|
+
LATER_THAN_DATETIME_VALIDATOR,
|
|
21
|
+
EARLIER_THAN_DATETIME_VALIDATOR
|
|
18
22
|
} from "@digigov/form/validators/utils";
|
|
19
23
|
import { INT_VALIDATOR } from "@digigov/form/validators/utils/int";
|
|
20
24
|
import { NUMBER_VALIDATOR } from "@digigov/form/validators/utils/number";
|
|
21
|
-
const getYUPTypeMap = () => {
|
|
25
|
+
const getYUPTypeMap = (validatorRegistry) => {
|
|
22
26
|
const yupTypeMap = {
|
|
23
27
|
file: (field) => {
|
|
24
28
|
return yup.mixed().transform((value) => {
|
|
25
|
-
if (!value.length) {
|
|
29
|
+
if (!value || value.length === 0) {
|
|
26
30
|
return null;
|
|
27
31
|
}
|
|
28
32
|
return value;
|
|
29
33
|
}).nullable().test(FILE_MAX_SIZE_VALIDATOR(field));
|
|
30
34
|
},
|
|
31
|
-
string:
|
|
35
|
+
string: (field) => {
|
|
36
|
+
if (field.trim) {
|
|
37
|
+
return yup.string().trim();
|
|
38
|
+
} else {
|
|
39
|
+
return yup.string();
|
|
40
|
+
}
|
|
41
|
+
},
|
|
32
42
|
boolean: () => {
|
|
33
43
|
return yup.boolean().nullable().transform((value) => {
|
|
34
44
|
if (value === "" || typeof value === "string") return null;
|
|
@@ -42,7 +52,10 @@ const getYUPTypeMap = () => {
|
|
|
42
52
|
},
|
|
43
53
|
array: (field) => {
|
|
44
54
|
if (typeof field.extra.of === "object") {
|
|
45
|
-
|
|
55
|
+
if (field.required) {
|
|
56
|
+
field.extra.min = 1;
|
|
57
|
+
}
|
|
58
|
+
let arrayValidator = yup.array().nullable().of(yupTypeMap[field.extra.of.type](field.extra.of));
|
|
46
59
|
if (field.extra.length)
|
|
47
60
|
arrayValidator = arrayValidator.length(field.extra.length, {
|
|
48
61
|
key: "form.error.array.length",
|
|
@@ -71,18 +84,19 @@ const getYUPTypeMap = () => {
|
|
|
71
84
|
return yup.array().of(yup.string());
|
|
72
85
|
}
|
|
73
86
|
},
|
|
74
|
-
number: () => yup.mixed().transform((_, val) => val !== "" ? Number(val) :
|
|
75
|
-
int: () => yup.mixed().transform((_, val) => val !== "" ? Number(val) :
|
|
76
|
-
email: () => yup.string().email("form.error.email"),
|
|
77
|
-
afm: () => yup.string().test(AFM_VALIDATOR),
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
87
|
+
number: () => yup.mixed().transform((_, val) => val !== "" ? Number(val) : void 0).test(NUMBER_VALIDATOR()),
|
|
88
|
+
int: () => yup.mixed().transform((_, val) => val !== "" ? Number(val) : void 0).test(NUMBER_VALIDATOR()).test(INT_VALIDATOR()),
|
|
89
|
+
email: (field) => field.trim ? yup.string().trim().email("form.error.email") : yup.string().email("form.error.email"),
|
|
90
|
+
afm: (field) => field.trim ? yup.string().trim().test(AFM_VALIDATOR) : yup.string().test(AFM_VALIDATOR),
|
|
91
|
+
amka: (field) => field.trim ? yup.string().trim().test(AMKA_VALIDATOR) : yup.string().test(AMKA_VALIDATOR),
|
|
92
|
+
uuid4: (field) => field.trim ? yup.string().trim().test(UUID4_VALIDATOR) : yup.string().test(UUID4_VALIDATOR),
|
|
93
|
+
iban: (field) => field.trim ? yup.string().trim().test(IBAN_VALIDATOR(field)) : yup.string().trim().test(IBAN_VALIDATOR(field)),
|
|
94
|
+
otp: (field) => yup.string().trim().test(OTP_VALIDATOR(field)),
|
|
81
95
|
text: (field) => {
|
|
82
96
|
if (field?.extra?.limit?.max || !!field?.extra?.limit?.min) {
|
|
83
|
-
return yup.string().test(TEXT_LIMIT_VALIDATOR(field));
|
|
97
|
+
return field.trim ? yup.string().trim().test(TEXT_LIMIT_VALIDATOR(field)) : yup.string().test(TEXT_LIMIT_VALIDATOR(field));
|
|
84
98
|
} else {
|
|
85
|
-
return yup.string();
|
|
99
|
+
return field.trim ? yup.string().trim() : yup.string();
|
|
86
100
|
}
|
|
87
101
|
},
|
|
88
102
|
image: (field) => {
|
|
@@ -93,9 +107,9 @@ const getYUPTypeMap = () => {
|
|
|
93
107
|
return value;
|
|
94
108
|
}).nullable().test(FILE_MAX_SIZE_VALIDATOR(field)).test(IMAGE_DIMENSION_VALIDATOR(field));
|
|
95
109
|
},
|
|
96
|
-
postal_code: (field) => yup.string().test(POSTALCODE_VALIDATOR(field)),
|
|
97
|
-
mobile_phone: () => yup.string().test(MOBILE_PHONE_VALIDATOR),
|
|
98
|
-
phone_number: (field) => yup.string().test(PHONE_NUMBER_VALIDATOR(field)),
|
|
110
|
+
postal_code: (field) => field.trim ? yup.string().trim().test(POSTALCODE_VALIDATOR(field)) : yup.string().test(POSTALCODE_VALIDATOR(field)),
|
|
111
|
+
mobile_phone: (field) => field.trim ? yup.string().trim().test(MOBILE_PHONE_VALIDATOR) : yup.string().test(MOBILE_PHONE_VALIDATOR),
|
|
112
|
+
phone_number: (field) => field.trim ? yup.string().trim().test(PHONE_NUMBER_VALIDATOR(field)) : yup.string().test(PHONE_NUMBER_VALIDATOR(field)),
|
|
99
113
|
"choice:multiple": () => yup.array().of(yup.string()).nullable(),
|
|
100
114
|
"choice:single": () => yup.string().nullable(),
|
|
101
115
|
date: (field) => {
|
|
@@ -109,15 +123,25 @@ const getYUPTypeMap = () => {
|
|
|
109
123
|
schema = schema.test(DATE_VALIDATOR);
|
|
110
124
|
}
|
|
111
125
|
return schema;
|
|
112
|
-
}
|
|
126
|
+
},
|
|
127
|
+
datetime: (field) => {
|
|
128
|
+
if (field?.extra?.min) {
|
|
129
|
+
return yup.string().test(LATER_THAN_DATETIME_VALIDATOR(field));
|
|
130
|
+
}
|
|
131
|
+
if (field?.extra?.max) {
|
|
132
|
+
return yup.string().test(EARLIER_THAN_DATETIME_VALIDATOR(field));
|
|
133
|
+
}
|
|
134
|
+
return yup.string().test(DATETIME_VALIDATOR);
|
|
135
|
+
},
|
|
136
|
+
...validatorRegistry
|
|
113
137
|
};
|
|
114
138
|
return yupTypeMap;
|
|
115
139
|
};
|
|
116
140
|
function useValidationSchema(fields, validatorRegistry) {
|
|
117
141
|
return useMemo(() => {
|
|
118
|
-
const yupTypeMap = getYUPTypeMap();
|
|
142
|
+
const yupTypeMap = getYUPTypeMap(validatorRegistry);
|
|
119
143
|
return getYupObjectShape(fields, yupTypeMap, validatorRegistry);
|
|
120
|
-
}, []);
|
|
144
|
+
}, [fields, validatorRegistry]);
|
|
121
145
|
}
|
|
122
146
|
export {
|
|
123
147
|
getYUPTypeMap,
|