@digigov/form 2.0.0-d0adc9fb → 2.0.0-d2ffc726
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/{inputs/inputsScenarios → 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 -26
- package/Field/FieldBase.d.ts +1 -1
- package/Field/FieldBase.js.map +2 -2
- package/Field/FieldBaseContainer/index.js +37 -17
- package/Field/FieldBaseContainer.d.ts +2 -2
- package/Field/FieldBaseContainer.js.map +2 -2
- package/Field/FieldConditional/index.js +4 -0
- package/Field/FieldConditional.d.ts +1 -1
- package/Field/FieldConditional.js.map +2 -2
- package/Field/index.d.ts +1 -1
- package/Field/index.js +24 -28
- package/Field/index.js.map +2 -2
- package/Field/types.d.ts +23 -12
- package/Field/utils/evaluateFieldWithConditions.d.ts +2 -2
- package/Field/utils/evaluateFieldWithConditions.js.map +2 -2
- package/Field/utils/resolveField/index.js +35 -0
- package/Field/utils/{calculateField → resolveField}/package.json +1 -1
- package/Field/utils/resolveField.d.ts +3 -0
- package/Field/utils/resolveField.js.map +7 -0
- package/Field/utils/useField/index.js +12 -3
- package/Field/utils/useField.d.ts +1 -1
- package/Field/utils/useField.js.map +2 -2
- package/FieldArray/BaseFieldArray/index.js +76 -0
- package/FieldArray/BaseFieldArray/package.json +6 -0
- package/FieldArray/BaseFieldArray.d.ts +5 -0
- package/FieldArray/BaseFieldArray.js.map +7 -0
- package/FieldArray/FieldArray.stories.d.ts +2 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayContainerDisplay/index.js +23 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayContainerDisplay/package.json +6 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayContainerDisplay.d.ts +9 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayContainerDisplay.js.map +7 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayDisplay.stories.d.ts +13 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay/index.js +184 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay/package.json +6 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay.d.ts +26 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay.js.map +7 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemHeader/index.js +11 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemHeader/package.json +6 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemHeader.d.ts +5 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemHeader.js.map +7 -0
- package/FieldArray/FormDialog/ArrayDisplay/__stories__/Cards.d.ts +2 -0
- package/FieldArray/FormDialog/ArrayDisplay/__stories__/Default.d.ts +2 -0
- package/FieldArray/FormDialog/ArrayDisplay/__stories__/ReadOnly.d.ts +2 -0
- package/FieldArray/FormDialog/ArrayDisplay/__stories__/ReadOnlyCards.d.ts +2 -0
- package/FieldArray/FormDialog/ArrayDisplay/__stories__/Sortable.d.ts +2 -0
- package/FieldArray/FormDialog/ArrayDisplay/__stories__/SortableCards.d.ts +2 -0
- package/FieldArray/FormDialog/ArrayDisplay/index.d.ts +15 -0
- package/FieldArray/FormDialog/ArrayDisplay/index.js +57 -0
- package/FieldArray/FormDialog/ArrayDisplay/index.js.map +7 -0
- package/{inputs/Input/inputsInputScenarios → FieldArray/FormDialog/ArrayDisplay}/package.json +1 -1
- package/FieldArray/FormDialog/ArrayEditModal/index.js +158 -0
- package/FieldArray/FormDialog/ArrayEditModal/package.json +6 -0
- package/FieldArray/FormDialog/ArrayEditModal.d.ts +26 -0
- package/FieldArray/FormDialog/ArrayEditModal.js.map +7 -0
- package/FieldArray/FormDialog/index.d.ts +19 -0
- package/FieldArray/FormDialog/index.js +213 -257
- package/FieldArray/FormDialog/index.js.map +7 -0
- package/FieldArray/__stories__/CardsWithError.d.ts +15 -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 +5 -2
- package/FieldArray/index.js +41 -57
- package/FieldArray/index.js.map +2 -2
- package/FieldObject/index.d.ts +7 -4
- package/FieldObject/index.js +30 -27
- package/FieldObject/index.js.map +2 -2
- package/Fieldset/FieldsetWithContext.js.map +1 -1
- package/Fieldset/index.d.ts +1 -1
- package/Fieldset/index.js.map +1 -1
- 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 +2 -2
- package/FormBuilder/index.js +186 -80
- package/FormBuilder/index.js.map +2 -2
- package/FormContext/index.js +6 -2
- package/FormContext.d.ts +3 -2
- 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 +12 -19
- package/MultiplicityField/add-objects.d.ts +1 -1
- package/MultiplicityField/add-objects.js.map +2 -2
- package/MultiplicityField/index.d.ts +2 -2
- package/MultiplicityField/index.js +6 -2
- package/MultiplicityField/index.js.map +2 -2
- package/MultiplicityField/types.d.ts +3 -2
- package/Questions/Questions.d.ts +1 -1
- package/Questions/Questions.js.map +1 -1
- package/Questions/Questions.stories.d.ts +2 -0
- package/Questions/QuestionsContext.d.ts +1 -1
- package/Questions/QuestionsContext.js.map +1 -1
- package/Questions/Step/Step.d.ts +1 -1
- package/Questions/Step/Step.js.map +1 -1
- package/Questions/Step/StepArrayReview.d.ts +1 -1
- package/Questions/Step/StepArrayReview.js.map +1 -1
- package/Questions/Step/StepContext.d.ts +1 -1
- package/Questions/Step/StepContext.js.map +1 -1
- package/Questions/Step/StepDescription.d.ts +1 -1
- package/Questions/Step/StepDescription.js.map +2 -2
- package/Questions/Step/StepForm.d.ts +2 -2
- package/Questions/Step/StepForm.js.map +1 -1
- package/Questions/Step/StepQuote.d.ts +1 -1
- package/Questions/Step/StepQuote.js.map +2 -2
- package/Questions/Step/StepTitle.d.ts +1 -1
- package/Questions/Step/StepTitle.js.map +2 -2
- package/Questions/Step/getAddMoreFields.d.ts +2 -2
- package/Questions/Step/getAddMoreFields.js.map +1 -1
- package/Questions/Step/types.d.ts +1 -1
- package/Questions/__stories__/Default.d.ts +1 -1
- package/Questions/getNextStep.d.ts +1 -1
- package/Questions/getNextStep.js.map +1 -1
- package/Questions/types.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 -25
- 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 +24 -25
- package/cjs/Field/index.js.map +2 -2
- package/cjs/Field/types.js.map +1 -1
- package/cjs/Field/utils/evaluateFieldWithConditions.js.map +2 -2
- package/cjs/Field/utils/resolveField/index.js +55 -0
- package/cjs/Field/utils/resolveField.js.map +7 -0
- package/cjs/Field/utils/useField/index.js +12 -3
- package/cjs/Field/utils/useField.js.map +2 -2
- package/cjs/FieldArray/BaseFieldArray/index.js +109 -0
- package/cjs/FieldArray/BaseFieldArray.js.map +7 -0
- package/cjs/FieldArray/FormDialog/ArrayDisplay/ArrayContainerDisplay/index.js +56 -0
- package/cjs/FieldArray/FormDialog/ArrayDisplay/ArrayContainerDisplay.js.map +7 -0
- package/cjs/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay/index.js +209 -0
- package/cjs/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay.js.map +7 -0
- package/cjs/{locales/el → FieldArray/FormDialog/ArrayDisplay/ArrayItemHeader}/index.js +16 -7
- package/cjs/FieldArray/FormDialog/ArrayDisplay/ArrayItemHeader.js.map +7 -0
- package/cjs/FieldArray/FormDialog/ArrayDisplay/index.js +90 -0
- package/cjs/FieldArray/FormDialog/ArrayDisplay/index.js.map +7 -0
- package/cjs/FieldArray/FormDialog/ArrayEditModal/index.js +186 -0
- package/cjs/FieldArray/FormDialog/ArrayEditModal.js.map +7 -0
- package/cjs/FieldArray/FormDialog/index.js +204 -243
- package/cjs/FieldArray/FormDialog/index.js.map +7 -0
- package/cjs/FieldArray/index.js +40 -56
- package/cjs/FieldArray/index.js.map +3 -3
- package/cjs/FieldObject/index.js +30 -24
- package/cjs/FieldObject/index.js.map +2 -2
- package/cjs/Fieldset/FieldsetWithContext.js.map +1 -1
- package/cjs/Fieldset/index.js.map +1 -1
- package/cjs/Fieldset/types.js.map +1 -1
- package/cjs/FormBuilder/index.js +188 -82
- package/cjs/FormBuilder/index.js.map +3 -3
- package/cjs/FormContext/index.js +7 -2
- package/cjs/FormContext.js.map +2 -2
- package/cjs/MultiplicityField/add-objects/index.js +11 -13
- package/cjs/MultiplicityField/add-objects.js.map +2 -2
- package/cjs/MultiplicityField/index.js +6 -2
- package/cjs/MultiplicityField/index.js.map +2 -2
- package/cjs/MultiplicityField/types.js.map +1 -1
- package/cjs/Questions/Questions.js.map +1 -1
- package/cjs/Questions/QuestionsContext.js.map +1 -1
- package/cjs/Questions/Step/Step.js.map +1 -1
- package/cjs/Questions/Step/StepArrayReview.js.map +1 -1
- package/cjs/Questions/Step/StepContext.js.map +1 -1
- package/cjs/Questions/Step/StepDescription.js.map +2 -2
- package/cjs/Questions/Step/StepForm.js.map +1 -1
- package/cjs/Questions/Step/StepQuote.js.map +2 -2
- package/cjs/Questions/Step/StepTitle.js.map +2 -2
- package/cjs/Questions/Step/getAddMoreFields.js.map +1 -1
- package/cjs/Questions/Step/types.js.map +1 -1
- package/cjs/Questions/getNextStep.js.map +1 -1
- package/cjs/Questions/types.js.map +1 -1
- package/cjs/hooks/useFieldFocusManager/index.js +135 -0
- package/cjs/hooks/useFieldFocusManager.js.map +7 -0
- package/cjs/hooks/utils/index.js +98 -0
- package/cjs/hooks/utils.js.map +7 -0
- package/cjs/inputs/AutoCompleteInput/index.js.map +2 -2
- package/cjs/inputs/Checkboxes/index.js +67 -62
- package/cjs/inputs/Checkboxes/index.js.map +2 -2
- package/cjs/inputs/DateInput/index.js +54 -19
- package/cjs/inputs/DateInput/index.js.map +2 -2
- package/cjs/inputs/DateTimeInput/index.js +83 -39
- package/cjs/inputs/DateTimeInput/index.js.map +2 -2
- 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 +42 -10
- package/cjs/inputs/ImageInput/index.js.map +2 -2
- package/cjs/inputs/Input/index.js +55 -55
- package/cjs/inputs/Input/index.js.map +2 -2
- package/cjs/inputs/Label/index.js.map +1 -1
- package/cjs/inputs/OtpInput/index.js +36 -30
- package/cjs/inputs/OtpInput/index.js.map +2 -2
- package/cjs/inputs/Radio/index.js +5 -4
- package/cjs/inputs/Radio/index.js.map +3 -3
- package/cjs/inputs/Select/index.js +5 -3
- package/cjs/inputs/Select/index.js.map +2 -2
- package/cjs/{Field/utils → inputs/registry}/index.js +7 -5
- package/cjs/inputs/registry.js.map +7 -0
- package/cjs/lazy/index.js +16 -10
- package/cjs/lazy.js.map +2 -2
- package/cjs/registry/index.js +31 -15
- package/cjs/registry.js.map +2 -2
- package/cjs/types.js.map +1 -1
- package/cjs/utils/index.js +20 -6
- package/cjs/utils.js.map +2 -2
- package/cjs/validators/index.js +33 -19
- package/cjs/validators/index.js.map +2 -2
- package/cjs/validators/types.js.map +1 -1
- 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 +26 -3
- package/cjs/validators/utils/date.js.map +2 -2
- package/cjs/validators/utils/datetime/index.js +118 -24
- package/cjs/validators/utils/datetime.js.map +2 -2
- package/cjs/validators/utils/email/index.js +39 -0
- package/cjs/validators/utils/email.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/iban.js.map +1 -1
- package/cjs/validators/utils/image.js.map +1 -1
- package/cjs/validators/utils/index.js +5 -1
- 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/otp.js.map +1 -1
- package/cjs/validators/utils/phone.js.map +1 -1
- package/cjs/validators/utils/postal_code.js.map +1 -1
- package/cjs/validators/utils/text_limit.js.map +1 -1
- package/hooks/useFieldFocusManager/index.js +116 -0
- package/hooks/useFieldFocusManager/package.json +6 -0
- package/hooks/useFieldFocusManager.d.ts +25 -0
- package/hooks/useFieldFocusManager.js.map +7 -0
- package/hooks/utils/index.js +73 -0
- package/{Field → hooks}/utils/package.json +1 -1
- package/hooks/utils.d.ts +18 -0
- package/hooks/utils.js.map +7 -0
- 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 +3 -3
- package/inputs/AutoCompleteInput/index.js +1 -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 +3 -3
- package/inputs/Checkboxes/index.js +67 -62
- 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 +2 -5
- package/inputs/DateInput/index.js +55 -20
- package/inputs/DateInput/index.js.map +2 -2
- package/inputs/DateTimeInput/DateTimeInput.stories.d.ts +10 -3
- package/inputs/DateTimeInput/__stories__/Default.d.ts +1 -1
- package/inputs/DateTimeInput/__stories__/WithDefaultValue.d.ts +3 -0
- package/inputs/DateTimeInput/__stories__/WithInitialValue.d.ts +3 -0
- package/inputs/DateTimeInput/__stories__/WithWrongDefaultValue.d.ts +3 -0
- package/inputs/DateTimeInput/__stories__/WithWrongInitialValue.d.ts +3 -0
- package/inputs/DateTimeInput/index.d.ts +2 -5
- package/inputs/DateTimeInput/index.js +84 -40
- package/inputs/DateTimeInput/index.js.map +2 -2
- 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 +18 -2
- package/inputs/FileInput/index.js +69 -31
- 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/ImageInput/__stories__/logo.d/package.json +6 -0
- package/inputs/ImageInput/__stories__/logo.d.js.map +7 -0
- package/inputs/ImageInput/index.d.ts +10 -2
- package/inputs/ImageInput/index.js +43 -11
- 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 +4 -3
- package/inputs/Input/index.js +55 -55
- 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 +1 -1
- package/inputs/Label/index.js.map +1 -1
- package/inputs/OtpInput/OtpInput.stories.d.ts +2 -0
- package/inputs/OtpInput/__stories__/Default.d.ts +1 -1
- package/inputs/OtpInput/index.d.ts +1 -5
- package/inputs/OtpInput/index.js +36 -30
- 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 +4 -4
- package/inputs/Radio/index.js +5 -4
- package/inputs/Radio/index.js.map +3 -3
- package/inputs/Select/Select.stories.d.ts +2 -0
- package/inputs/Select/__stories__/Default.d.ts +1 -1
- package/inputs/Select/index.d.ts +4 -3
- package/inputs/Select/index.js +5 -3
- package/inputs/Select/index.js.map +2 -2
- package/{Field/utils → inputs/registry}/index.js +4 -2
- package/{locales/el → inputs/registry}/package.json +1 -1
- package/{Field/utils/index.d.ts → inputs/registry.d.ts} +2 -1
- package/inputs/registry.js.map +7 -0
- package/lazy/index.js +16 -10
- package/package.json +8 -8
- package/registry/index.js +31 -15
- package/src/Field/ErrorGroup.tsx +84 -0
- package/src/Field/FieldBase.tsx +40 -26
- package/src/Field/FieldBaseContainer.tsx +69 -47
- package/src/Field/FieldConditional.tsx +5 -1
- package/src/Field/doc.mdx +202 -1
- package/src/Field/index.tsx +27 -37
- package/src/Field/types.tsx +24 -14
- package/src/Field/utils/evaluateFieldWithConditions.ts +5 -2
- package/src/Field/utils/resolveField.ts +58 -0
- package/src/Field/utils/useField.ts +12 -2
- package/src/FieldArray/BaseFieldArray.tsx +97 -0
- package/src/FieldArray/FieldArray.stories.js +2 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/ArrayContainerDisplay.tsx +45 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/ArrayDisplay.stories.js +14 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay.tsx +335 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/ArrayItemHeader.tsx +15 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/__stories__/Cards.tsx +88 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/__stories__/Default.tsx +93 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/__stories__/ReadOnly.tsx +79 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/__stories__/ReadOnlyCards.tsx +75 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/__stories__/Sortable.tsx +93 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/__stories__/SortableCards.tsx +88 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/index.test.tsx +44 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/index.tsx +67 -0
- package/src/FieldArray/FormDialog/ArrayEditModal.tsx +243 -0
- package/src/FieldArray/FormDialog/index.tsx +304 -0
- package/src/FieldArray/__stories__/CardsWithError.tsx +124 -0
- package/src/FieldArray/__stories__/Default.tsx +1 -1
- package/src/FieldArray/__stories__/WithExactLength.tsx +15 -78
- package/src/FieldArray/__stories__/WithModal.tsx +160 -0
- package/src/FieldArray/__tests__/fieldset-multiplicity.spec.tsx +271 -0
- package/src/FieldArray/__tests__/multiplicity-attachment.spec.tsx +280 -0
- package/src/FieldArray/__tests__/multiplicity-optional.spec.tsx +232 -0
- package/src/FieldArray/__tests__/multiplicity-required.spec.tsx +170 -0
- package/src/FieldArray/__tests__/nested-fieldset-multiplicity.spec.tsx +627 -0
- package/src/FieldArray/__tests__/preference-multiple-choice.spec.tsx +222 -0
- package/src/FieldArray/index.spec.tsx +355 -0
- package/src/FieldArray/index.test.tsx +12 -0
- package/src/FieldArray/index.tsx +49 -72
- package/src/FieldObject/index.tsx +40 -34
- package/src/Fieldset/FieldsetWithContext.tsx +1 -1
- package/src/Fieldset/index.tsx +1 -1
- 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/doc.mdx +9 -4
- package/src/FormBuilder/index.test.tsx +12 -0
- package/src/FormBuilder/index.tsx +223 -89
- package/src/FormBuilder/interaction.test.tsx +40 -0
- package/src/FormBuilder/scenarios.test.tsx +1002 -129
- package/src/FormContext.tsx +7 -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 +14 -21
- package/src/MultiplicityField/doc.mdx +101 -83
- package/src/MultiplicityField/index.test.tsx +4 -0
- package/src/MultiplicityField/index.tsx +8 -3
- package/src/MultiplicityField/types.ts +6 -2
- package/src/Questions/Questions.stories.js +3 -0
- package/src/Questions/Questions.tsx +2 -2
- package/src/Questions/QuestionsContext.tsx +1 -1
- package/src/Questions/Step/Step.tsx +1 -1
- package/src/Questions/Step/StepArrayReview.tsx +2 -2
- package/src/Questions/Step/StepContext.tsx +1 -1
- package/src/Questions/Step/StepDescription.tsx +2 -1
- package/src/Questions/Step/StepForm.tsx +2 -2
- package/src/Questions/Step/StepQuote.tsx +2 -1
- package/src/Questions/Step/StepTitle.tsx +2 -1
- package/src/Questions/Step/getAddMoreFields.tsx +2 -2
- package/src/Questions/Step/types.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/getNextStep.tsx +1 -1
- package/src/Questions/index.spec.tsx +8 -0
- package/src/Questions/index.test.tsx +4 -0
- package/src/Questions/types.tsx +1 -1
- package/src/doc.mdx +26 -11
- package/src/hooks/__tests__/useFieldFocusManager.spec.tsx +1079 -0
- package/src/hooks/__tests__/utils.spec.ts +568 -0
- package/src/hooks/useFieldFocusManager.ts +162 -0
- package/src/hooks/utils.ts +122 -0
- package/src/inputs/AutoCompleteInput/AutoComplete.stories.js +3 -0
- package/src/inputs/AutoCompleteInput/__stories__/Default.tsx +1 -1
- package/src/inputs/AutoCompleteInput/__stories__/Multiple.tsx +1 -1
- package/src/inputs/AutoCompleteInput/index.test.tsx +4 -0
- package/src/inputs/AutoCompleteInput/index.tsx +4 -6
- 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 +95 -90
- package/src/inputs/DateInput/DateInput.stories.js +7 -0
- package/src/inputs/DateInput/__stories__/Default.tsx +1 -1
- package/src/inputs/DateInput/__stories__/WithDefaultValue.tsx +26 -0
- package/src/inputs/DateInput/__stories__/WithInitialValue.tsx +28 -0
- package/src/inputs/DateInput/__stories__/WithWrongDefaultValue.tsx +26 -0
- package/src/inputs/DateInput/__stories__/WithWrongInitialValue.tsx +28 -0
- package/src/inputs/DateInput/index.test.tsx +20 -0
- package/src/inputs/DateInput/index.tsx +68 -20
- package/src/inputs/DateTimeInput/DateTimeInput.stories.js +12 -6
- package/src/inputs/DateTimeInput/__stories__/Default.tsx +1 -1
- package/src/inputs/DateTimeInput/__stories__/WithDefaultValue.tsx +26 -0
- package/src/inputs/DateTimeInput/__stories__/WithInitialValue.tsx +28 -0
- package/src/inputs/DateTimeInput/__stories__/WithWrongDefaultValue.tsx +26 -0
- package/src/inputs/DateTimeInput/__stories__/WithWrongInitialValue.tsx +28 -0
- package/src/inputs/DateTimeInput/index.test.tsx +27 -5
- package/src/inputs/DateTimeInput/index.tsx +97 -40
- 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 +106 -38
- package/src/inputs/ImageInput/ImageInput.stories.js +5 -1
- package/src/inputs/ImageInput/__stories__/Default.tsx +1 -1
- package/src/inputs/ImageInput/__stories__/MaxSize.tsx +3 -2
- package/src/inputs/ImageInput/__stories__/{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 +101 -48
- 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 +1 -1
- package/src/inputs/Input/__stories__/MobilePhone.tsx +1 -1
- package/src/inputs/Input/__stories__/PhoneNumber.tsx +1 -1
- package/src/inputs/Input/__stories__/PostalCode.tsx +1 -1
- package/src/inputs/Input/__stories__/String.tsx +1 -1
- package/src/inputs/Input/__stories__/StringWithTrimValidation.tsx +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 +76 -71
- 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 +1 -1
- 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 +43 -33
- 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 +29 -21
- 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 +10 -6
- package/src/{Field/utils/index.ts → inputs/registry.ts} +5 -1
- package/src/lazy.js +16 -10
- package/src/registry.js +31 -15
- package/src/types.tsx +14 -5
- package/src/utils.ts +30 -8
- package/src/validators/index.ts +68 -28
- package/src/validators/types.ts +1 -1
- package/src/validators/utils/amka.ts +39 -0
- package/src/validators/utils/date.ts +30 -6
- package/src/validators/utils/datetime.ts +123 -31
- package/src/validators/utils/email.ts +11 -0
- package/src/validators/utils/file.ts +35 -21
- package/src/validators/utils/iban.ts +2 -2
- package/src/validators/utils/image.ts +2 -2
- package/src/validators/utils/index.ts +6 -3
- package/src/validators/utils/int.ts +2 -2
- package/src/validators/utils/number.ts +2 -2
- package/src/validators/utils/otp.ts +2 -2
- package/src/validators/utils/phone.ts +2 -2
- package/src/validators/utils/postal_code.ts +2 -2
- package/src/validators/utils/text_limit.ts +2 -2
- package/types.d.ts +10 -4
- package/types.js.map +1 -1
- package/utils/index.js +20 -6
- package/utils.d.ts +3 -1
- package/utils.js.map +2 -2
- package/validators/index.d.ts +6 -6
- package/validators/index.js +34 -19
- package/validators/index.js.map +2 -2
- package/validators/types.d.ts +1 -1
- package/validators/utils/amka/index.js +36 -0
- package/validators/utils/amka/package.json +6 -0
- package/validators/utils/amka.d.ts +6 -0
- package/validators/utils/amka.js.map +7 -0
- package/validators/utils/date/index.js +26 -3
- package/validators/utils/date.d.ts +3 -3
- package/validators/utils/date.js.map +2 -2
- package/validators/utils/datetime/index.js +118 -24
- package/validators/utils/datetime.d.ts +3 -3
- package/validators/utils/datetime.js.map +2 -2
- package/validators/utils/email/index.js +16 -0
- package/validators/utils/email/package.json +6 -0
- package/validators/utils/email.d.ts +5 -0
- package/validators/utils/email.js.map +7 -0
- package/validators/utils/file/index.js +30 -17
- package/validators/utils/file.d.ts +2 -2
- package/validators/utils/file.js.map +2 -2
- package/validators/utils/iban.d.ts +2 -2
- package/validators/utils/iban.js.map +1 -1
- package/validators/utils/image.d.ts +2 -2
- package/validators/utils/image.js.map +1 -1
- package/validators/utils/index.d.ts +3 -2
- package/validators/utils/index.js +4 -1
- package/validators/utils/index.js.map +2 -2
- package/validators/utils/int/index.js +1 -1
- package/validators/utils/int.d.ts +1 -1
- package/validators/utils/int.js.map +2 -2
- package/validators/utils/number/index.js +1 -1
- package/validators/utils/number.d.ts +1 -1
- package/validators/utils/number.js.map +2 -2
- package/validators/utils/otp.d.ts +2 -2
- package/validators/utils/otp.js.map +1 -1
- package/validators/utils/phone.d.ts +2 -2
- package/validators/utils/phone.js.map +1 -1
- package/validators/utils/postal_code.d.ts +2 -2
- package/validators/utils/postal_code.js.map +1 -1
- package/validators/utils/text_limit.d.ts +2 -2
- package/validators/utils/text_limit.js.map +1 -1
- package/Field/utils/calculateField/index.js +0 -27
- package/Field/utils/calculateField.d.ts +0 -2
- package/Field/utils/calculateField.js.map +0 -7
- package/Field/utils/index.js.map +0 -7
- package/FieldArray/FormDialog.d.ts +0 -53
- package/FieldArray/FormDialog.js.map +0 -7
- package/FormBuilder/index.test.d.ts +0 -1
- package/FormBuilder/scenarios.test.d.ts +0 -88
- package/MultiplicityField/index.test.d.ts +0 -1
- package/Questions/index.spec.d.ts +0 -1
- package/Questions/index.test.d.ts +0 -1
- package/cjs/Field/utils/calculateField/index.js +0 -50
- package/cjs/Field/utils/calculateField.js.map +0 -7
- package/cjs/Field/utils/index.js.map +0 -7
- package/cjs/FieldArray/FormDialog.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/inputsScenarios/index.js +0 -533
- package/cjs/inputs/inputsScenarios.js.map +0 -7
- package/cjs/locales/el.js.map +0 -7
- package/inputs/AutoCompleteInput/index.test.d.ts +0 -1
- package/inputs/Checkboxes/index.test.d.ts +0 -1
- package/inputs/DateInput/index.test.d.ts +0 -1
- package/inputs/DateTimeInput/index.test.d.ts +0 -1
- package/inputs/FileInput/index.test.d.ts +0 -1
- package/inputs/ImageInput/__stories__/WithInvalidImageSize.d.ts +0 -3
- package/inputs/ImageInput/index.test.d.ts +0 -1
- package/inputs/Input/index.test.d.ts +0 -1
- package/inputs/Input/inputsInputScenarios/index.js +0 -406
- package/inputs/Input/inputsInputScenarios.d.ts +0 -57
- package/inputs/Input/inputsInputScenarios.js.map +0 -7
- package/inputs/Label/index.test.d.ts +0 -1
- package/inputs/OtpInput/index.test.d.ts +0 -1
- package/inputs/Radio/index.test.d.ts +0 -1
- package/inputs/Select/index.test.d.ts +0 -1
- package/inputs/inputsScenarios/index.js +0 -499
- package/inputs/inputsScenarios.d.ts +0 -296
- package/inputs/inputsScenarios.js.map +0 -7
- package/locales/el/index.js +0 -6
- package/locales/el.d.ts +0 -2
- package/locales/el.js.map +0 -7
- package/src/Field/utils/calculateField.ts +0 -49
- package/src/FieldArray/FormDialog.tsx +0 -379
- package/src/inputs/Input/inputsInputScenarios.ts +0 -404
- package/src/inputs/inputsScenarios.ts +0 -496
- package/src/locales/el.ts +0 -3
- /package/{FieldArray/index.test.d.ts → hooks/__tests__/utils.spec.d.ts} +0 -0
package/src/types.tsx
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { UseFormReturn, UseFormProps } from 'react-hook-form';
|
|
2
|
-
import {
|
|
3
|
-
FieldComponentRegistry,
|
|
1
|
+
import type { UseFormReturn, UseFormProps, ErrorOption } from 'react-hook-form';
|
|
2
|
+
import type {
|
|
4
3
|
FieldLabelProps,
|
|
5
4
|
FieldSpec,
|
|
6
5
|
FormData,
|
|
7
6
|
} from '@digigov/form/Field/types';
|
|
8
|
-
import {
|
|
7
|
+
import type { FieldComponentRegistry } from '@digigov/form/inputs/registry';
|
|
8
|
+
import type { ValidatorSchema } from '@digigov/form/validators/types';
|
|
9
9
|
export * from '@digigov/form/Field/types';
|
|
10
10
|
export interface FieldError {
|
|
11
11
|
message: string;
|
|
@@ -18,25 +18,33 @@ export interface FieldsetSpec {
|
|
|
18
18
|
body?: React.ReactNode;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
export type registerFieldFocus = (
|
|
22
|
+
fieldName: string,
|
|
23
|
+
element: HTMLElement
|
|
24
|
+
) => (name: string) => void;
|
|
25
|
+
|
|
21
26
|
export interface FormContextProps {
|
|
22
27
|
fieldsetsMap?: Record<string, FieldsetSpec>;
|
|
23
28
|
fieldsMap: Record<string, FieldSpec>;
|
|
24
29
|
control: UseFormReturn['control'];
|
|
25
30
|
register: UseFormReturn['register'];
|
|
26
31
|
trigger: UseFormReturn['trigger'];
|
|
32
|
+
setError: UseFormReturn['setError'];
|
|
27
33
|
clearErrors: UseFormReturn['clearErrors'];
|
|
28
34
|
watch: UseFormReturn['watch'];
|
|
29
35
|
getFieldState: UseFormReturn['getFieldState'];
|
|
30
36
|
setValue: UseFormReturn['setValue'];
|
|
31
37
|
getValues: UseFormReturn['getValues'];
|
|
38
|
+
getValuesFromParentForm?: UseFormReturn['getValues'];
|
|
32
39
|
unregister: UseFormReturn['unregister'];
|
|
33
40
|
formState: UseFormReturn['formState'];
|
|
34
41
|
reset: UseFormReturn['reset'];
|
|
35
42
|
resetField: UseFormReturn['resetField'];
|
|
36
43
|
registerField: (field: FieldSpec) => void;
|
|
44
|
+
registerFieldFocus: registerFieldFocus;
|
|
37
45
|
errors: UseFormReturn['formState']['errors'];
|
|
38
46
|
componentRegistry?: FieldComponentRegistry;
|
|
39
|
-
submit: () => Promise<void
|
|
47
|
+
submit: () => Promise<void> | void;
|
|
40
48
|
}
|
|
41
49
|
|
|
42
50
|
export interface FormBuilderProps {
|
|
@@ -54,6 +62,7 @@ export interface FormBuilderProps {
|
|
|
54
62
|
componentRegistry?: FieldComponentRegistry;
|
|
55
63
|
grid?: boolean;
|
|
56
64
|
controlledFieldsOnly?: boolean;
|
|
65
|
+
errors?: ErrorOption;
|
|
57
66
|
}
|
|
58
67
|
|
|
59
68
|
export interface FormBaseProps
|
package/src/utils.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { validateFieldsNatively } from '@hookform/resolvers';
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
2
|
+
import type { FieldError } from 'react-hook-form';
|
|
3
|
+
import { appendErrors } from 'react-hook-form';
|
|
4
|
+
import type * as Yup from 'yup';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Why `path!` ? because it could be `undefined` in some case
|
|
@@ -13,6 +14,7 @@ const parseErrorSchema = (
|
|
|
13
14
|
return (error.inner || []).reduce<Record<string, FieldError>>(
|
|
14
15
|
(previous, error) => {
|
|
15
16
|
error.path = error.path?.replace(/\[([0-9]+)\]/g, '.$1');
|
|
17
|
+
// error.path = error.path?.replace(/\["(.*?)"\]/g, '$1');
|
|
16
18
|
if (!previous[error.path!]) {
|
|
17
19
|
previous[error.path!] = { message: error.message, type: error.type! };
|
|
18
20
|
}
|
|
@@ -37,6 +39,26 @@ const parseErrorSchema = (
|
|
|
37
39
|
{}
|
|
38
40
|
);
|
|
39
41
|
};
|
|
42
|
+
function isPlainObject(obj) {
|
|
43
|
+
return (
|
|
44
|
+
typeof obj === 'object' &&
|
|
45
|
+
obj !== null &&
|
|
46
|
+
Object.prototype.toString.call(obj) === '[object Object]'
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
function flattenObject(obj, prefix = '') {
|
|
50
|
+
return Object.keys(obj).reduce((acc, key) => {
|
|
51
|
+
const prefixedKey = prefix ? `${prefix}.${key}` : key;
|
|
52
|
+
|
|
53
|
+
if (isPlainObject(obj[key])) {
|
|
54
|
+
Object.assign(acc, flattenObject(obj[key], prefixedKey));
|
|
55
|
+
} else {
|
|
56
|
+
acc[prefixedKey] = obj[key];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return acc;
|
|
60
|
+
}, {});
|
|
61
|
+
}
|
|
40
62
|
|
|
41
63
|
export const yupResolver =
|
|
42
64
|
(schema: any, schemaOptions: any = {}, resolverOptions: any = {}) =>
|
|
@@ -51,7 +73,7 @@ export const yupResolver =
|
|
|
51
73
|
const result = await schema[
|
|
52
74
|
resolverOptions.mode === 'sync' ? 'validateSync' : 'validate'
|
|
53
75
|
](
|
|
54
|
-
values,
|
|
76
|
+
flattenObject(values),
|
|
55
77
|
Object.assign({ abortEarly: false }, schemaOptions, { context })
|
|
56
78
|
);
|
|
57
79
|
|
|
@@ -67,13 +89,13 @@ export const yupResolver =
|
|
|
67
89
|
throw e;
|
|
68
90
|
}
|
|
69
91
|
|
|
70
|
-
const parsed = parseErrorSchema(
|
|
71
|
-
e,
|
|
72
|
-
!options.shouldUseNativeValidation && options.criteriaMode === 'all'
|
|
73
|
-
);
|
|
74
92
|
return {
|
|
75
93
|
values: {},
|
|
76
|
-
errors:
|
|
94
|
+
errors: parseErrorSchema(
|
|
95
|
+
e,
|
|
96
|
+
!options.shouldUseNativeValidation && options.criteriaMode === 'all'
|
|
97
|
+
),
|
|
98
|
+
options,
|
|
77
99
|
};
|
|
78
100
|
}
|
|
79
101
|
};
|
package/src/validators/index.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import { MutableRefObject
|
|
1
|
+
import type { MutableRefObject } from 'react';
|
|
2
|
+
import { useMemo } from 'react';
|
|
2
3
|
import * as yup from 'yup';
|
|
3
|
-
import { AnyObjectSchema, StringSchema } from 'yup';
|
|
4
|
-
import { RequiredArraySchema } from 'yup/lib/array';
|
|
5
|
-
import Lazy from 'yup/lib/Lazy';
|
|
6
|
-
import { MixedSchema } from 'yup/lib/mixed';
|
|
7
|
-
import { TypeOfShape, AssertsShape } from 'yup/lib/object';
|
|
8
|
-
import { AnyObject } from 'yup/lib/types';
|
|
9
|
-
import { FieldSpec } from '@digigov/form/types';
|
|
10
|
-
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
4
|
+
import type { AnyObjectSchema, StringSchema } from 'yup';
|
|
5
|
+
import type { RequiredArraySchema } from 'yup/lib/array';
|
|
6
|
+
import type Lazy from 'yup/lib/Lazy';
|
|
7
|
+
import type { MixedSchema } from 'yup/lib/mixed';
|
|
8
|
+
import type { TypeOfShape, AssertsShape } from 'yup/lib/object';
|
|
9
|
+
import type { AnyObject } from 'yup/lib/types';
|
|
10
|
+
import type { FieldSpec } from '@digigov/form/types';
|
|
11
|
+
import type { ValidatorSchema } from '@digigov/form/validators/types';
|
|
11
12
|
import {
|
|
12
13
|
getYupObjectShape,
|
|
13
14
|
AFM_VALIDATOR,
|
|
15
|
+
AMKA_VALIDATOR,
|
|
14
16
|
FILE_MAX_SIZE_VALIDATOR,
|
|
15
17
|
IBAN_VALIDATOR,
|
|
16
18
|
OTP_VALIDATOR,
|
|
@@ -27,16 +29,19 @@ import {
|
|
|
27
29
|
LATER_THAN_DATETIME_VALIDATOR,
|
|
28
30
|
EARLIER_THAN_DATETIME_VALIDATOR,
|
|
29
31
|
} from '@digigov/form/validators/utils';
|
|
32
|
+
import { EMAIL_VALIDATOR } from '@digigov/form/validators/utils/email';
|
|
30
33
|
import { INT_VALIDATOR } from '@digigov/form/validators/utils/int';
|
|
31
34
|
import { NUMBER_VALIDATOR } from '@digigov/form/validators/utils/number';
|
|
32
35
|
|
|
33
|
-
export const getYUPTypeMap = (
|
|
36
|
+
export const getYUPTypeMap = (
|
|
37
|
+
validatorRegistry?: Record<string, any>
|
|
38
|
+
): Record<string, any> => {
|
|
34
39
|
const yupTypeMap = {
|
|
35
40
|
file: (field): MixedSchema => {
|
|
36
41
|
return yup
|
|
37
42
|
.mixed()
|
|
38
43
|
.transform((value) => {
|
|
39
|
-
if (!value.length) {
|
|
44
|
+
if (!value || value.length === 0) {
|
|
40
45
|
return null;
|
|
41
46
|
}
|
|
42
47
|
return value;
|
|
@@ -44,7 +49,13 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
44
49
|
.nullable()
|
|
45
50
|
.test(FILE_MAX_SIZE_VALIDATOR(field));
|
|
46
51
|
},
|
|
47
|
-
string: (): yup.StringSchema =>
|
|
52
|
+
string: (field): yup.StringSchema => {
|
|
53
|
+
if (field.trim) {
|
|
54
|
+
return yup.string().trim();
|
|
55
|
+
} else {
|
|
56
|
+
return yup.string();
|
|
57
|
+
}
|
|
58
|
+
},
|
|
48
59
|
boolean: (): yup.BooleanSchema<
|
|
49
60
|
boolean | null | undefined,
|
|
50
61
|
AnyObject,
|
|
@@ -75,10 +86,13 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
75
86
|
if (typeof field.extra.of === 'object') {
|
|
76
87
|
// else if the field is an object then it is a scalar type
|
|
77
88
|
// eg. number, string etc.
|
|
89
|
+
if (field.required) {
|
|
90
|
+
field.extra.min = 1;
|
|
91
|
+
}
|
|
78
92
|
let arrayValidator = yup
|
|
79
93
|
.array()
|
|
80
|
-
.
|
|
81
|
-
.
|
|
94
|
+
.nullable()
|
|
95
|
+
.of(yupTypeMap[field.extra.of.type](field.extra.of));
|
|
82
96
|
if (field.extra.length)
|
|
83
97
|
arrayValidator = arrayValidator.length(field.extra.length, {
|
|
84
98
|
key: 'form.error.array.length',
|
|
@@ -91,12 +105,14 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
91
105
|
key: 'form.error.array.min',
|
|
92
106
|
context: {
|
|
93
107
|
min: field.extra.min,
|
|
108
|
+
max: field.extra.max || undefined,
|
|
94
109
|
},
|
|
95
110
|
});
|
|
96
111
|
if (field.extra.max)
|
|
97
112
|
arrayValidator = arrayValidator.max(field.extra.max, {
|
|
98
113
|
key: 'form.error.array.max',
|
|
99
114
|
context: {
|
|
115
|
+
min: field.extra.min || undefined,
|
|
100
116
|
max: field.extra.max,
|
|
101
117
|
},
|
|
102
118
|
});
|
|
@@ -111,26 +127,43 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
111
127
|
number: (): MixedSchema =>
|
|
112
128
|
yup
|
|
113
129
|
.mixed()
|
|
114
|
-
.transform((_, val) => (val !== '' ? Number(val) :
|
|
130
|
+
.transform((_, val) => (val !== '' ? Number(val) : undefined))
|
|
115
131
|
.test(NUMBER_VALIDATOR()),
|
|
116
132
|
int: (): MixedSchema =>
|
|
117
133
|
yup
|
|
118
134
|
.mixed()
|
|
119
|
-
.transform((_, val) => (val !== '' ? Number(val) :
|
|
135
|
+
.transform((_, val) => (val !== '' ? Number(val) : undefined))
|
|
120
136
|
.test(NUMBER_VALIDATOR())
|
|
121
137
|
.test(INT_VALIDATOR()),
|
|
122
|
-
email: (): yup.StringSchema =>
|
|
123
|
-
|
|
124
|
-
|
|
138
|
+
email: (field): yup.StringSchema =>
|
|
139
|
+
field.trim
|
|
140
|
+
? yup.string().trim().test(EMAIL_VALIDATOR)
|
|
141
|
+
: yup.string().test(EMAIL_VALIDATOR),
|
|
142
|
+
afm: (field): yup.StringSchema =>
|
|
143
|
+
field.trim
|
|
144
|
+
? yup.string().trim().test(AFM_VALIDATOR)
|
|
145
|
+
: yup.string().test(AFM_VALIDATOR),
|
|
146
|
+
amka: (field): yup.StringSchema =>
|
|
147
|
+
field.trim
|
|
148
|
+
? yup.string().trim().test(AMKA_VALIDATOR)
|
|
149
|
+
: yup.string().test(AMKA_VALIDATOR),
|
|
150
|
+
uuid4: (field): yup.StringSchema =>
|
|
151
|
+
field.trim
|
|
152
|
+
? yup.string().trim().test(UUID4_VALIDATOR)
|
|
153
|
+
: yup.string().test(UUID4_VALIDATOR),
|
|
125
154
|
iban: (field): yup.StringSchema =>
|
|
126
|
-
|
|
155
|
+
field.trim
|
|
156
|
+
? yup.string().trim().test(IBAN_VALIDATOR(field))
|
|
157
|
+
: yup.string().trim().test(IBAN_VALIDATOR(field)),
|
|
127
158
|
otp: (field): yup.StringSchema =>
|
|
128
159
|
yup.string().trim().test(OTP_VALIDATOR(field)),
|
|
129
160
|
text: (field): yup.StringSchema => {
|
|
130
161
|
if (field?.extra?.limit?.max || !!field?.extra?.limit?.min) {
|
|
131
|
-
return
|
|
162
|
+
return field.trim
|
|
163
|
+
? yup.string().trim().test(TEXT_LIMIT_VALIDATOR(field))
|
|
164
|
+
: yup.string().test(TEXT_LIMIT_VALIDATOR(field));
|
|
132
165
|
} else {
|
|
133
|
-
return yup.string();
|
|
166
|
+
return field.trim ? yup.string().trim() : yup.string();
|
|
134
167
|
}
|
|
135
168
|
},
|
|
136
169
|
image: (field): MixedSchema => {
|
|
@@ -147,11 +180,17 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
147
180
|
.test(IMAGE_DIMENSION_VALIDATOR(field));
|
|
148
181
|
},
|
|
149
182
|
postal_code: (field): yup.StringSchema =>
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
183
|
+
field.trim
|
|
184
|
+
? yup.string().trim().test(POSTALCODE_VALIDATOR(field))
|
|
185
|
+
: yup.string().test(POSTALCODE_VALIDATOR(field)),
|
|
186
|
+
mobile_phone: (field): yup.StringSchema =>
|
|
187
|
+
field.trim
|
|
188
|
+
? yup.string().trim().test(MOBILE_PHONE_VALIDATOR)
|
|
189
|
+
: yup.string().test(MOBILE_PHONE_VALIDATOR),
|
|
153
190
|
phone_number: (field): yup.StringSchema =>
|
|
154
|
-
|
|
191
|
+
field.trim
|
|
192
|
+
? yup.string().trim().test(PHONE_NUMBER_VALIDATOR(field))
|
|
193
|
+
: yup.string().test(PHONE_NUMBER_VALIDATOR(field)),
|
|
155
194
|
'choice:multiple': (): yup.ArraySchema<
|
|
156
195
|
yup.StringSchema<string | undefined, AnyObject, string | undefined>,
|
|
157
196
|
AnyObject,
|
|
@@ -190,6 +229,7 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
190
229
|
}
|
|
191
230
|
return yup.string().test(DATETIME_VALIDATOR);
|
|
192
231
|
},
|
|
232
|
+
...validatorRegistry,
|
|
193
233
|
};
|
|
194
234
|
return yupTypeMap;
|
|
195
235
|
};
|
|
@@ -201,7 +241,7 @@ export function useValidationSchema(
|
|
|
201
241
|
validatorRegistry?: Record<string, ValidatorSchema[]>
|
|
202
242
|
): Lazy<any, unknown> | AnyObjectSchema | void {
|
|
203
243
|
return useMemo(() => {
|
|
204
|
-
const yupTypeMap = getYUPTypeMap();
|
|
244
|
+
const yupTypeMap = getYUPTypeMap(validatorRegistry);
|
|
205
245
|
return getYupObjectShape(fields, yupTypeMap, validatorRegistry);
|
|
206
|
-
}, []);
|
|
246
|
+
}, [fields, validatorRegistry]);
|
|
207
247
|
}
|
package/src/validators/types.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import * as yup from 'yup';
|
|
1
|
+
import type * as yup from 'yup';
|
|
2
2
|
export type ValidatorSchema = yup.TestConfig;
|
|
@@ -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
|
+
};
|
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import dayjs from 'dayjs';
|
|
2
2
|
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
3
|
-
import { FieldSpec } from '@digigov/form/types';
|
|
4
|
-
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
3
|
+
import type { FieldSpec } from '@digigov/form/types';
|
|
4
|
+
import type { ValidatorSchema } from '@digigov/form/validators/types';
|
|
5
5
|
|
|
6
6
|
dayjs.extend(customParseFormat);
|
|
7
7
|
|
|
8
8
|
const VALID_DATE_FORMATS = ['DD/MM/YYYY'];
|
|
9
9
|
const DATE_CACHE = {};
|
|
10
|
+
const onlyNumbersRegex = /^\d+$/;
|
|
10
11
|
|
|
11
12
|
const getDate = (v: string) => {
|
|
12
13
|
return DATE_CACHE[v] ? DATE_CACHE[v] : dayjs(v, VALID_DATE_FORMATS, true);
|
|
13
14
|
};
|
|
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
|
+
|
|
15
20
|
// Function to check partial date completion
|
|
16
21
|
const checkPartialDate = (value: string) => {
|
|
17
|
-
console.log("value.split('/')", value.split('/'));
|
|
18
22
|
const [day, month, year] = value.split('/');
|
|
19
23
|
if (day && !month && !year) {
|
|
20
24
|
return 'form.error.date.invalid_month_year';
|
|
@@ -33,9 +37,29 @@ const checkPartialDate = (value: string) => {
|
|
|
33
37
|
}
|
|
34
38
|
if (!day && month && year) {
|
|
35
39
|
return 'form.error.date.invalid_day';
|
|
36
|
-
} else {
|
|
37
|
-
return 'form.error.date.invalid';
|
|
38
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';
|
|
39
63
|
};
|
|
40
64
|
|
|
41
65
|
export const LATER_THAN_VALIDATOR = (field: FieldSpec): ValidatorSchema => {
|
|
@@ -96,7 +120,7 @@ export const EARLIER_THAN_VALIDATOR = (field: FieldSpec): ValidatorSchema => {
|
|
|
96
120
|
|
|
97
121
|
export const DATE_VALIDATOR = {
|
|
98
122
|
name: 'date-validator',
|
|
99
|
-
message: (v): string => {
|
|
123
|
+
message: (v): string | object => {
|
|
100
124
|
return checkPartialDate(v.value);
|
|
101
125
|
},
|
|
102
126
|
test: function (value: string) {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import dayjs from 'dayjs';
|
|
2
2
|
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
3
|
-
import { FieldSpec } from '@digigov/form/types';
|
|
4
|
-
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
3
|
+
import type { FieldSpec } from '@digigov/form/types';
|
|
4
|
+
import type { ValidatorSchema } from '@digigov/form/validators/types';
|
|
5
5
|
|
|
6
6
|
dayjs.extend(customParseFormat);
|
|
7
7
|
|
|
8
8
|
const VALID_DATETIME_FORMATS = ['DD/MM/YYYY HH:mm'];
|
|
9
9
|
const DATETIME_CACHE = {};
|
|
10
|
+
const onlyNumbersRegex = /^\d+$/;
|
|
10
11
|
|
|
11
12
|
const getDateTime = (v: string) => {
|
|
12
13
|
return DATETIME_CACHE[v]
|
|
@@ -14,54 +15,145 @@ const getDateTime = (v: string) => {
|
|
|
14
15
|
: dayjs(v, VALID_DATETIME_FORMATS, true);
|
|
15
16
|
};
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
const getDaysInMonth = (month: number, year: number): number => {
|
|
19
|
+
return dayjs(`${year}-${month}-01`).daysInMonth(); // e.g. 29 for Feb 2024
|
|
20
|
+
};
|
|
21
|
+
|
|
18
22
|
const checkPartialDateTime = (value: string) => {
|
|
19
23
|
const [datePart, timePart] = value.split(' ');
|
|
20
|
-
const [day, month, year] = datePart
|
|
21
|
-
const [hours, minutes] = timePart
|
|
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);
|
|
22
32
|
|
|
23
|
-
|
|
24
|
-
|
|
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) {
|
|
25
67
|
return 'form.error.datetime.invalid_month_year';
|
|
26
68
|
}
|
|
27
|
-
if (!
|
|
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) {
|
|
28
76
|
return 'form.error.datetime.invalid_day_year';
|
|
29
77
|
}
|
|
30
|
-
if (!
|
|
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) {
|
|
31
85
|
return 'form.error.datetime.invalid_day_month';
|
|
32
86
|
}
|
|
33
|
-
if (
|
|
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) {
|
|
34
100
|
return 'form.error.datetime.invalid_year';
|
|
35
101
|
}
|
|
36
|
-
if (
|
|
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) {
|
|
37
109
|
return 'form.error.datetime.invalid_month';
|
|
38
110
|
}
|
|
39
|
-
if (!
|
|
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) {
|
|
40
118
|
return 'form.error.datetime.invalid_day';
|
|
41
119
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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';
|
|
46
132
|
}
|
|
47
|
-
|
|
48
|
-
|
|
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
|
+
};
|
|
49
142
|
}
|
|
50
|
-
if (
|
|
51
|
-
return 'form.error.datetime.
|
|
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';
|
|
52
152
|
}
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
const minutesNum = parseInt(minutes);
|
|
56
|
-
if (hoursNum < 0 || hoursNum > 23) {
|
|
57
|
-
return 'form.error.datetime.invalid_hours_range';
|
|
58
|
-
}
|
|
59
|
-
if (minutesNum < 0 || minutesNum > 59) {
|
|
60
|
-
return 'form.error.datetime.invalid_minutes_range';
|
|
61
|
-
}
|
|
153
|
+
if (minutesNum < 0 || minutesNum > 59) {
|
|
154
|
+
return 'form.error.datetime.invalid_minutes_range';
|
|
62
155
|
}
|
|
63
156
|
}
|
|
64
|
-
|
|
65
157
|
return 'form.error.datetime.invalid';
|
|
66
158
|
};
|
|
67
159
|
|
|
@@ -119,7 +211,7 @@ export const EARLIER_THAN_DATETIME_VALIDATOR = (
|
|
|
119
211
|
|
|
120
212
|
export const DATETIME_VALIDATOR = {
|
|
121
213
|
name: 'datetime-validator',
|
|
122
|
-
message: (v): string => {
|
|
214
|
+
message: (v): string | object => {
|
|
123
215
|
return checkPartialDateTime(v.value);
|
|
124
216
|
},
|
|
125
217
|
test: function (value: string) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const EMAIL_VALIDATOR = {
|
|
2
|
+
name: 'email-validator',
|
|
3
|
+
message: 'form.error.email',
|
|
4
|
+
test: (value: string): boolean => {
|
|
5
|
+
if (!value) return true;
|
|
6
|
+
const EMAIL_REGEX =
|
|
7
|
+
// eslint-disable-next-line no-useless-escape
|
|
8
|
+
/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
9
|
+
return EMAIL_REGEX.test(value);
|
|
10
|
+
},
|
|
11
|
+
};
|