@digigov/form 2.0.0-daaf7bdf → 2.0.0-e20fed09
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 +38 -18
- 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 +21 -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 +87 -29
- package/FieldArray/index.js.map +2 -2
- package/FieldObject/index.d.ts +5 -0
- package/FieldObject/index.js +32 -17
- package/FieldObject/index.js.map +2 -2
- package/Fieldset/index.d.ts +1 -1
- package/Fieldset/index.js +5 -5
- package/Fieldset/index.js.map +2 -2
- package/Fieldset/types.d.ts +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 +94 -11
- 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 +10 -6
- package/MultiplicityField/add-objects.js.map +2 -2
- package/MultiplicityField/index.js +17 -11
- 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/Step/StepTitle/index.js +4 -3
- package/Questions/Step/StepTitle.d.ts +1 -1
- package/Questions/Step/StepTitle.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 +37 -17
- 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 +85 -27
- package/cjs/FieldArray/index.js.map +3 -3
- package/cjs/FieldObject/index.js +32 -17
- package/cjs/FieldObject/index.js.map +3 -3
- package/cjs/Fieldset/index.js +10 -10
- package/cjs/Fieldset/index.js.map +3 -3
- package/cjs/Fieldset/types.js.map +1 -1
- package/cjs/FormBuilder/index.js +94 -11
- package/cjs/FormBuilder/index.js.map +3 -3
- package/cjs/FormContext/index.js +9 -4
- package/cjs/FormContext.js.map +3 -3
- package/cjs/MultiplicityField/add-objects/index.js +14 -10
- package/cjs/MultiplicityField/add-objects.js.map +3 -3
- package/cjs/MultiplicityField/index.js +16 -15
- package/cjs/MultiplicityField/index.js.map +3 -3
- 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/Questions/Step/StepTitle/index.js +5 -5
- package/cjs/Questions/Step/StepTitle.js.map +3 -3
- package/cjs/inputs/AutoCompleteInput/index.js +8 -7
- package/cjs/inputs/AutoCompleteInput/index.js.map +3 -3
- package/cjs/inputs/Checkboxes/index.js +9 -9
- package/cjs/inputs/Checkboxes/index.js.map +3 -3
- package/cjs/inputs/DateInput/index.js +51 -22
- package/cjs/inputs/DateInput/index.js.map +3 -3
- package/cjs/inputs/DateTimeInput/index.js +245 -0
- package/cjs/inputs/DateTimeInput/index.js.map +7 -0
- package/cjs/inputs/FileInput/index.js +72 -35
- package/cjs/inputs/FileInput/index.js.map +3 -3
- 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 +54 -18
- package/cjs/inputs/ImageInput/index.js.map +3 -3
- package/cjs/inputs/Input/index.js +12 -4
- package/cjs/inputs/Input/index.js.map +2 -2
- package/cjs/inputs/Label/index.js +3 -3
- package/cjs/inputs/Label/index.js.map +3 -3
- package/cjs/inputs/OtpInput/index.js +1 -0
- package/cjs/inputs/OtpInput/index.js.map +2 -2
- package/cjs/inputs/Radio/index.js +12 -13
- package/cjs/inputs/Radio/index.js.map +3 -3
- package/cjs/inputs/Select/index.js +11 -5
- package/cjs/inputs/Select/index.js.map +3 -3
- package/cjs/inputs/inputsScenarios/index.js +6 -12
- package/cjs/inputs/inputsScenarios.js.map +2 -2
- package/cjs/{lazy/index.js → lazy.js} +49 -35
- package/cjs/lazy.js.map +3 -3
- package/cjs/locales/el.js.map +1 -1
- package/cjs/{registry/index.js → registry.js} +72 -62
- 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 +55 -85
- package/cjs/validators/index.js.map +3 -3
- 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 +161 -0
- package/cjs/validators/utils/date.js.map +7 -0
- 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 +10 -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 +10 -7
- 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 +10 -6
- 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 +54 -22
- 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 +76 -36
- 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 +54 -18
- 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 +12 -4
- 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 +2 -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 +8 -5
- 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 -4
- 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 -67
- package/locales/el.js.map +1 -1
- package/package.json +8 -8
- package/registry/index.js +116 -107
- package/src/Field/ErrorGroup.tsx +84 -0
- package/src/Field/FieldBase.tsx +39 -24
- package/src/Field/FieldBaseContainer.tsx +70 -47
- package/src/Field/FieldConditional.tsx +6 -2
- package/src/Field/doc.mdx +207 -0
- package/src/Field/index.tsx +20 -5
- package/src/Field/types.tsx +42 -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 +119 -54
- package/src/FieldObject/index.tsx +41 -20
- package/src/Fieldset/index.tsx +5 -5
- package/src/Fieldset/types.tsx +2 -2
- 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/{FormBuilder.mdx → doc.mdx} +27 -35
- package/src/FormBuilder/index.test.tsx +12 -0
- package/src/FormBuilder/index.tsx +104 -14
- 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 +11 -9
- package/src/MultiplicityField/{MultiplicityField.mdx → doc.mdx} +112 -98
- package/src/MultiplicityField/index.test.tsx +4 -0
- package/src/MultiplicityField/index.tsx +17 -12
- 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/Step/StepTitle.tsx +4 -3
- package/src/Questions/__snapshots__/index.spec.tsx.snap +11 -5
- package/src/Questions/__stories__/Default.tsx +1 -1
- package/src/Questions/{index.mdx → doc.mdx} +30 -53
- package/src/Questions/index.spec.tsx +14 -2
- package/src/Questions/index.test.tsx +4 -0
- package/src/create-simple-form.mdx +2 -6
- package/src/{index.mdx → doc.mdx} +29 -18
- 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.mdx → doc.mdx} +2 -13
- package/src/inputs/AutoCompleteInput/index.test.tsx +4 -0
- package/src/inputs/AutoCompleteInput/index.tsx +32 -28
- 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.mdx → doc.mdx} +5 -15
- package/src/inputs/Checkboxes/index.test.tsx +4 -0
- package/src/inputs/Checkboxes/index.tsx +28 -28
- 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.mdx → doc.mdx} +1 -8
- package/src/inputs/DateInput/index.test.tsx +20 -0
- package/src/inputs/DateInput/index.tsx +58 -21
- 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.mdx → doc.mdx} +1 -5
- package/src/inputs/FileInput/index.test.tsx +8 -0
- package/src/inputs/FileInput/index.tsx +106 -41
- 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 +3 -1
- package/src/inputs/ImageInput/__stories__/logo.d.ts +4 -0
- package/src/inputs/ImageInput/__stories__/logo.png +0 -0
- package/src/inputs/ImageInput/doc.mdx +23 -0
- package/src/inputs/ImageInput/index.test.tsx +8 -4
- package/src/inputs/ImageInput/index.tsx +103 -50
- 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 +3 -2
- package/src/inputs/Input/__stories__/MobilePhone.tsx +2 -1
- package/src/inputs/Input/__stories__/PhoneNumber.tsx +2 -1
- package/src/inputs/Input/__stories__/PostalCode.tsx +2 -1
- 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/doc.mdx +56 -0
- package/src/inputs/Input/index.test.tsx +16 -0
- package/src/inputs/Input/index.tsx +30 -12
- package/src/inputs/Label/Label.stories.js +3 -0
- package/src/inputs/Label/__stories__/Default.tsx +1 -1
- package/src/inputs/Label/doc.mdx +14 -0
- package/src/inputs/Label/index.test.tsx +4 -0
- package/src/inputs/Label/index.tsx +2 -6
- package/src/inputs/OtpInput/OtpInput.stories.js +3 -0
- package/src/inputs/OtpInput/__stories__/Default.tsx +1 -1
- package/src/inputs/OtpInput/{index.mdx → doc.mdx} +1 -8
- 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.mdx → doc.mdx} +5 -15
- package/src/inputs/Radio/index.test.tsx +4 -0
- package/src/inputs/Radio/index.tsx +59 -56
- package/src/inputs/Select/Select.stories.js +3 -0
- package/src/inputs/Select/__stories__/Default.tsx +1 -1
- package/src/inputs/Select/{index.mdx → doc.mdx} +1 -5
- package/src/inputs/Select/index.test.tsx +4 -0
- package/src/inputs/Select/index.tsx +18 -7
- package/src/inputs/inputsScenarios.ts +36 -42
- package/src/installation.mdx +2 -5
- package/src/lazy.js +77 -64
- package/src/locales/el.ts +1 -1
- package/src/registry.js +108 -100
- package/src/types.tsx +4 -3
- package/src/utils.ts +29 -8
- package/src/validators/index.ts +103 -91
- package/src/validators/utils/amka.ts +39 -0
- package/src/validators/utils/date.ts +131 -0
- package/src/validators/utils/datetime.ts +222 -0
- package/src/validators/utils/file.ts +33 -17
- package/src/validators/utils/index.ts +6 -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 +63 -86
- 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 +126 -0
- package/validators/utils/date/package.json +6 -0
- package/validators/utils/date.d.ts +9 -0
- package/validators/utils/date.js.map +7 -0
- 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 +3 -0
- package/validators/utils/index.js +6 -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 -71
- 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 -67
- package/cjs/inputs/Input/__stories__/LandlineNumber.js.map +0 -7
- package/cjs/inputs/Input/__stories__/MobilePhone/index.js +0 -67
- package/cjs/inputs/Input/__stories__/MobilePhone.js.map +0 -7
- package/cjs/inputs/Input/__stories__/PhoneNumber/index.js +0 -66
- package/cjs/inputs/Input/__stories__/PhoneNumber.js.map +0 -7
- package/cjs/inputs/Input/__stories__/PostalCode/index.js +0 -64
- 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 -38
- 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 -34
- 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 -34
- 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 -33
- 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 -31
- 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 -77
- package/lazy.js.map +0 -7
- package/registry.d.ts +0 -70
- package/registry.js.map +0 -7
- package/src/Field/index.mdx +0 -6
- package/src/inputs/ImageInput/index.mdx +0 -19
- package/src/inputs/Input/index.mdx +0 -95
- package/src/inputs/Input/inputsInputScenarios.ts +0 -405
- package/src/inputs/Label/index.mdx +0 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
function digitSum(number) {
|
|
2
|
+
const sum = number > 9 ? 1 : 0;
|
|
3
|
+
return sum + (number % 10);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function validateAMKA(amka: string): boolean {
|
|
7
|
+
// Validate that the last digit is the correct check digit (created using the
|
|
8
|
+
// Luhn algorithm https://en.wikipedia.org/wiki/Luhn_algorithm).
|
|
9
|
+
amka = String(amka);
|
|
10
|
+
const checkDigitIndex = amka.length - 1;
|
|
11
|
+
let sum = 0;
|
|
12
|
+
amka
|
|
13
|
+
.substring(0, checkDigitIndex)
|
|
14
|
+
.split('')
|
|
15
|
+
.reverse()
|
|
16
|
+
.forEach(function (value, index) {
|
|
17
|
+
const weight = ((index + 1) % 2) + 1;
|
|
18
|
+
sum += digitSum(parseInt(value, 10) * weight);
|
|
19
|
+
});
|
|
20
|
+
const sumMod10 = sum % 10;
|
|
21
|
+
if (sumMod10 === 0) {
|
|
22
|
+
return amka.substring(checkDigitIndex) === '0';
|
|
23
|
+
} else {
|
|
24
|
+
return amka.substring(checkDigitIndex) === 10 - sumMod10 + '';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const AMKA_VALIDATOR = {
|
|
29
|
+
name: 'amka-validator',
|
|
30
|
+
message: 'form.error.amka',
|
|
31
|
+
test: (value): boolean => {
|
|
32
|
+
if (!value) return true;
|
|
33
|
+
const AMKA_REGEX = /^[0-9]{11}$/;
|
|
34
|
+
if (!AMKA_REGEX.test(value) || value === '00000000000') {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
return validateAMKA(value);
|
|
38
|
+
},
|
|
39
|
+
};
|
|
@@ -0,0 +1,131 @@
|
|
|
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_DATE_FORMATS = ['DD/MM/YYYY'];
|
|
9
|
+
const DATE_CACHE = {};
|
|
10
|
+
const onlyNumbersRegex = /^\d+$/;
|
|
11
|
+
|
|
12
|
+
const getDate = (v: string) => {
|
|
13
|
+
return DATE_CACHE[v] ? DATE_CACHE[v] : dayjs(v, VALID_DATE_FORMATS, true);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const getDaysInMonth = (month: number, year: number): number => {
|
|
17
|
+
return dayjs(`${year}-${month}-01`).daysInMonth(); // e.g. 29 for Feb 2024
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Function to check partial date completion
|
|
21
|
+
const checkPartialDate = (value: string) => {
|
|
22
|
+
const [day, month, year] = value.split('/');
|
|
23
|
+
if (day && !month && !year) {
|
|
24
|
+
return 'form.error.date.invalid_month_year';
|
|
25
|
+
}
|
|
26
|
+
if (!day && month && !year) {
|
|
27
|
+
return 'form.error.date.invalid_day_year';
|
|
28
|
+
}
|
|
29
|
+
if (!day && !month && year) {
|
|
30
|
+
return 'form.error.date.invalid_day_month';
|
|
31
|
+
}
|
|
32
|
+
if (day && month && !year) {
|
|
33
|
+
return 'form.error.date.invalid_year';
|
|
34
|
+
}
|
|
35
|
+
if (day && !month && year) {
|
|
36
|
+
return 'form.error.date.invalid_month';
|
|
37
|
+
}
|
|
38
|
+
if (!day && month && year) {
|
|
39
|
+
return 'form.error.date.invalid_day';
|
|
40
|
+
}
|
|
41
|
+
if (day && month) {
|
|
42
|
+
const dayNum = parseInt(day);
|
|
43
|
+
const monthNum = parseInt(month);
|
|
44
|
+
const validYear = onlyNumbersRegex.test(year) ? year : undefined;
|
|
45
|
+
if (!validYear || year.length < 4) {
|
|
46
|
+
return 'form.error.date.invalid';
|
|
47
|
+
}
|
|
48
|
+
const yearNum = parseInt(validYear);
|
|
49
|
+
const maxDay = getDaysInMonth(monthNum, yearNum);
|
|
50
|
+
if (dayNum < 1 || dayNum > maxDay) {
|
|
51
|
+
return {
|
|
52
|
+
key: 'form.error.date.invalid_day_range',
|
|
53
|
+
context: {
|
|
54
|
+
maxDay: maxDay,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
if (monthNum < 1 || monthNum > 12) {
|
|
59
|
+
return 'form.error.datetime.invalid_month_range';
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return 'form.error.date.invalid';
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const LATER_THAN_VALIDATOR = (field: FieldSpec): ValidatorSchema => {
|
|
66
|
+
let minDate;
|
|
67
|
+
const params = field.extra || {};
|
|
68
|
+
if (params.min === 'now') {
|
|
69
|
+
const today = new Date();
|
|
70
|
+
minDate = new Date(today);
|
|
71
|
+
} else {
|
|
72
|
+
minDate = getDate(params.min).toDate();
|
|
73
|
+
}
|
|
74
|
+
const minPreviousDate = new Date(minDate);
|
|
75
|
+
minPreviousDate.setDate(minDate.getDate() - 1);
|
|
76
|
+
return {
|
|
77
|
+
name: 'later-than',
|
|
78
|
+
message: {
|
|
79
|
+
key: 'form.error.date.later_than',
|
|
80
|
+
context: {
|
|
81
|
+
minDate: minPreviousDate.toLocaleDateString(),
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
test: function (value: string) {
|
|
85
|
+
if (!value) return true;
|
|
86
|
+
const date = getDate(value);
|
|
87
|
+
const isValid = +date.toDate() > +minDate;
|
|
88
|
+
return isValid;
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export const EARLIER_THAN_VALIDATOR = (field: FieldSpec): ValidatorSchema => {
|
|
94
|
+
let maxDate;
|
|
95
|
+
const params = field.extra || {};
|
|
96
|
+
if (params.max === 'now') {
|
|
97
|
+
const today = new Date();
|
|
98
|
+
maxDate = new Date(today);
|
|
99
|
+
} else {
|
|
100
|
+
maxDate = getDate(params.max).toDate();
|
|
101
|
+
}
|
|
102
|
+
const maxNextDate = new Date(maxDate);
|
|
103
|
+
maxNextDate.setDate(maxDate.getDate() + 1);
|
|
104
|
+
return {
|
|
105
|
+
name: 'earlier-than',
|
|
106
|
+
message: {
|
|
107
|
+
key: 'form.error.date.earlier_than',
|
|
108
|
+
context: {
|
|
109
|
+
maxDate: maxNextDate.toLocaleDateString(),
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
test: function (value: string) {
|
|
113
|
+
if (!value) return true;
|
|
114
|
+
const date = getDate(value);
|
|
115
|
+
const isValid = +date.toDate() < +maxDate;
|
|
116
|
+
return isValid;
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export const DATE_VALIDATOR = {
|
|
122
|
+
name: 'date-validator',
|
|
123
|
+
message: (v): string | object => {
|
|
124
|
+
return checkPartialDate(v.value);
|
|
125
|
+
},
|
|
126
|
+
test: function (value: string) {
|
|
127
|
+
if (!value) return true;
|
|
128
|
+
const date = getDate(value);
|
|
129
|
+
return date.isValid();
|
|
130
|
+
},
|
|
131
|
+
};
|
|
@@ -0,0 +1,222 @@
|
|
|
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 (hasDay && hasMonth && !hasYear && hasHours && hasMinutes) {
|
|
100
|
+
return 'form.error.datetime.invalid_year';
|
|
101
|
+
}
|
|
102
|
+
if (hasDay && !hasMonth && hasYear && hasHours && !hasMinutes) {
|
|
103
|
+
return 'form.error.datetime.invalid_month_minutes';
|
|
104
|
+
}
|
|
105
|
+
if (hasDay && !hasMonth && hasYear && !hasHours && hasMinutes) {
|
|
106
|
+
return 'form.error.datetime.invalid_month_hours';
|
|
107
|
+
}
|
|
108
|
+
if (hasDay && !hasMonth && hasYear && hasHours && hasMinutes) {
|
|
109
|
+
return 'form.error.datetime.invalid_month';
|
|
110
|
+
}
|
|
111
|
+
if (!hasDay && hasMonth && hasYear && hasHours && !hasMinutes) {
|
|
112
|
+
return 'form.error.datetime.invalid_day_minutes';
|
|
113
|
+
}
|
|
114
|
+
if (!hasDay && hasMonth && hasYear && !hasHours && hasMinutes) {
|
|
115
|
+
return 'form.error.datetime.invalid_day_hours';
|
|
116
|
+
}
|
|
117
|
+
if (!hasDay && hasMonth && hasYear && hasHours && hasMinutes) {
|
|
118
|
+
return 'form.error.datetime.invalid_day';
|
|
119
|
+
}
|
|
120
|
+
if (!hasDay && !hasMonth && !hasYear && hasHours && !hasMinutes) {
|
|
121
|
+
return 'form.error.datetime.invalid_day_month_year_minutes';
|
|
122
|
+
}
|
|
123
|
+
if (hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
124
|
+
return 'form.error.datetime.invalid_hours_minutes';
|
|
125
|
+
}
|
|
126
|
+
if (day && month) {
|
|
127
|
+
const dayNum = parseInt(day);
|
|
128
|
+
const monthNum = parseInt(month);
|
|
129
|
+
const validYear = onlyNumbersRegex.test(year) ? year : undefined;
|
|
130
|
+
if (!validYear || year.length < 4) {
|
|
131
|
+
return 'form.error.datetime.invalid';
|
|
132
|
+
}
|
|
133
|
+
const yearNum = parseInt(validYear);
|
|
134
|
+
const maxDay = getDaysInMonth(monthNum, yearNum);
|
|
135
|
+
if (dayNum < 1 || dayNum > maxDay) {
|
|
136
|
+
return {
|
|
137
|
+
key: 'form.error.datetime.invalid_day_range',
|
|
138
|
+
context: {
|
|
139
|
+
maxDay: maxDay,
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
if (monthNum < 1 || monthNum > 12) {
|
|
144
|
+
return 'form.error.datetime.invalid_month_range';
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (hours && minutes) {
|
|
148
|
+
const hoursNum = parseInt(hours);
|
|
149
|
+
const minutesNum = parseInt(minutes);
|
|
150
|
+
if (hoursNum < 0 || hoursNum > 23) {
|
|
151
|
+
return 'form.error.datetime.invalid_hours_range';
|
|
152
|
+
}
|
|
153
|
+
if (minutesNum < 0 || minutesNum > 59) {
|
|
154
|
+
return 'form.error.datetime.invalid_minutes_range';
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return 'form.error.datetime.invalid';
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export const LATER_THAN_DATETIME_VALIDATOR = (
|
|
161
|
+
field: FieldSpec
|
|
162
|
+
): ValidatorSchema => {
|
|
163
|
+
let minDateTime;
|
|
164
|
+
const params = field.extra || {};
|
|
165
|
+
if (params.min === 'now') {
|
|
166
|
+
minDateTime = dayjs();
|
|
167
|
+
} else {
|
|
168
|
+
minDateTime = getDateTime(params.min);
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
name: 'later-than-datetime',
|
|
172
|
+
message: {
|
|
173
|
+
key: 'form.error.datetime.later_than',
|
|
174
|
+
context: {
|
|
175
|
+
minDateTime: minDateTime.format('DD/MM/YYYY HH:mm'),
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
test: function (value: string) {
|
|
179
|
+
if (!value) return true;
|
|
180
|
+
const datetime = getDateTime(value);
|
|
181
|
+
return datetime.isValid() && datetime.isAfter(minDateTime);
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
export const EARLIER_THAN_DATETIME_VALIDATOR = (
|
|
187
|
+
field: FieldSpec
|
|
188
|
+
): ValidatorSchema => {
|
|
189
|
+
let maxDateTime;
|
|
190
|
+
const params = field.extra || {};
|
|
191
|
+
if (params.max === 'now') {
|
|
192
|
+
maxDateTime = dayjs();
|
|
193
|
+
} else {
|
|
194
|
+
maxDateTime = getDateTime(params.max);
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
name: 'earlier-than-datetime',
|
|
198
|
+
message: {
|
|
199
|
+
key: 'form.error.datetime.earlier_than',
|
|
200
|
+
context: {
|
|
201
|
+
maxDateTime: maxDateTime.format('DD/MM/YYYY HH:mm'),
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
test: function (value: string) {
|
|
205
|
+
if (!value) return true;
|
|
206
|
+
const datetime = getDateTime(value);
|
|
207
|
+
return datetime.isValid() && datetime.isBefore(maxDateTime);
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
export const DATETIME_VALIDATOR = {
|
|
213
|
+
name: 'datetime-validator',
|
|
214
|
+
message: (v): string | object => {
|
|
215
|
+
return checkPartialDateTime(v.value);
|
|
216
|
+
},
|
|
217
|
+
test: function (value: string) {
|
|
218
|
+
if (!value) return true;
|
|
219
|
+
const datetime = getDateTime(value);
|
|
220
|
+
return datetime.isValid();
|
|
221
|
+
},
|
|
222
|
+
};
|
|
@@ -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';
|
|
@@ -11,6 +12,8 @@ export * from '@digigov/form/validators/utils/phone';
|
|
|
11
12
|
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';
|
|
15
|
+
export * from '@digigov/form/validators/utils/date';
|
|
16
|
+
export * from '@digigov/form/validators/utils/datetime';
|
|
14
17
|
|
|
15
18
|
export function getYupField(field: FieldSpec, yupTypeMap: Record<string, any>) {
|
|
16
19
|
const yupField = yupTypeMap[field?.type || 'string'] || yupTypeMap['string'];
|
|
@@ -96,7 +99,9 @@ export function getYupObjectShape(
|
|
|
96
99
|
|
|
97
100
|
return yup.lazy(function () {
|
|
98
101
|
const fieldSchemas = computeShape(
|
|
99
|
-
Object.values(fields.current)
|
|
102
|
+
Object.values(fields.current).filter(
|
|
103
|
+
(f: FieldSpec) => !f.key.includes('.')
|
|
104
|
+
) as FieldSpec[],
|
|
100
105
|
yupTypeMap,
|
|
101
106
|
validatorRegistry
|
|
102
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
|
}>;
|