@digigov/form 2.0.0-6452adf3 → 2.0.0-66d7c5e2
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 -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 +29 -28
- package/Field/index.js.map +2 -2
- package/Field/types.d.ts +31 -19
- 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/{Questions/Questions.stories → Field/utils/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 +17 -2
- 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/DateInput/DateInput.stories → FieldArray/FormDialog/ArrayDisplay}/package.json +1 -1
- package/FieldArray/FormDialog/ArrayEditModal/index.js +158 -0
- package/{inputs/Checkboxes/Checkboxes.stories → FieldArray/FormDialog/ArrayEditModal}/package.json +1 -1
- 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 +231 -0
- package/FieldArray/FormDialog/index.js.map +7 -0
- package/{inputs/inputsScenarios → FieldArray/FormDialog}/package.json +1 -1
- 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 +10 -2
- package/FieldArray/index.js +60 -43
- package/FieldArray/index.js.map +2 -2
- package/FieldObject/index.d.ts +8 -3
- package/FieldObject/index.js +32 -24
- 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 +189 -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 +16 -21
- 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 +5 -1
- package/MultiplicityField/index.js.map +2 -2
- package/MultiplicityField/types.d.ts +3 -3
- package/Questions/Questions/index.js +5 -4
- package/Questions/Questions.d.ts +1 -1
- package/Questions/Questions.js.map +2 -2
- 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 +2 -2
- 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 +29 -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 +17 -2
- 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/{FormBuilder/__stories__/Default → FieldArray/FormDialog/ArrayDisplay/ArrayContainerDisplay}/index.js +22 -31
- 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/{FormBuilder/FormBuilder.stories → FieldArray/FormDialog/ArrayDisplay/ArrayItemHeader}/index.js +12 -13
- 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 +258 -0
- package/cjs/FieldArray/FormDialog/index.js.map +7 -0
- package/cjs/FieldArray/index.js +59 -42
- package/cjs/FieldArray/index.js.map +3 -3
- package/cjs/FieldObject/index.js +32 -21
- 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 +191 -82
- 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 +15 -15
- package/cjs/MultiplicityField/add-objects.js.map +2 -2
- package/cjs/MultiplicityField/index.js +5 -1
- package/cjs/MultiplicityField/index.js.map +2 -2
- package/cjs/MultiplicityField/types.js.map +1 -1
- package/cjs/Questions/Questions/index.js +5 -4
- package/cjs/Questions/Questions.js.map +2 -2
- package/cjs/Questions/QuestionsContext.js.map +1 -1
- package/cjs/Questions/Step/Step.js.map +1 -1
- package/cjs/Questions/Step/StepArrayReview.js.map +2 -2
- 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 +4 -3
- package/cjs/inputs/AutoCompleteInput/index.js.map +2 -2
- package/cjs/inputs/Checkboxes/index.js +67 -61
- package/cjs/inputs/Checkboxes/index.js.map +2 -2
- package/cjs/inputs/DateInput/index.js +57 -22
- package/cjs/inputs/DateInput/index.js.map +2 -2
- package/cjs/inputs/DateTimeInput/index.js +250 -0
- package/cjs/inputs/DateTimeInput/index.js.map +7 -0
- package/cjs/inputs/FileInput/index.js +68 -30
- package/cjs/inputs/FileInput/index.js.map +2 -2
- package/cjs/inputs/ImageInput/__stories__/logo.d/index.js +1 -0
- package/cjs/inputs/ImageInput/__stories__/logo.d.js.map +7 -0
- package/cjs/inputs/ImageInput/index.js +48 -11
- package/cjs/inputs/ImageInput/index.js.map +2 -2
- package/cjs/inputs/Input/index.js +55 -49
- package/cjs/inputs/Input/index.js.map +2 -2
- package/cjs/inputs/Label/index.js.map +2 -2
- package/cjs/inputs/OtpInput/index.js +36 -30
- package/cjs/inputs/OtpInput/index.js.map +2 -2
- package/cjs/inputs/Radio/index.js +6 -4
- package/cjs/inputs/Radio/index.js.map +3 -3
- package/cjs/inputs/Select/index.js +9 -2
- package/cjs/inputs/Select/index.js.map +2 -2
- package/cjs/{Field/utils → inputs/registry}/index.js +13 -5
- package/cjs/inputs/registry.js.map +7 -0
- package/cjs/lazy/index.js +54 -40
- package/cjs/lazy.js.map +3 -3
- package/cjs/registry/index.js +85 -63
- 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 +56 -24
- 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 +245 -0
- package/cjs/validators/utils/datetime.js.map +7 -0
- package/cjs/{Form.stories → validators/utils/email}/index.js +20 -7
- 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 +8 -2
- package/cjs/validators/utils/index.js.map +2 -2
- package/cjs/validators/utils/int/index.js +1 -1
- package/cjs/validators/utils/int.js.map +2 -2
- package/cjs/validators/utils/number/index.js +1 -1
- package/cjs/validators/utils/number.js.map +2 -2
- package/cjs/validators/utils/otp.js.map +1 -1
- package/cjs/validators/utils/phone.js.map +2 -2
- package/cjs/validators/utils/postal_code.js.map +1 -1
- package/cjs/validators/utils/text_limit.js.map +1 -1
- package/cjs/validators/utils/uuid4.js.map +2 -2
- 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 +4 -4
- package/inputs/AutoCompleteInput/index.js +5 -6
- 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 +4 -4
- package/inputs/Checkboxes/index.js +67 -61
- 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 -6
- package/inputs/DateInput/index.js +58 -23
- 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 +10 -0
- package/inputs/DateTimeInput/index.js +220 -0
- package/inputs/DateTimeInput/index.js.map +7 -0
- package/inputs/DateTimeInput/package.json +6 -0
- 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/{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 +10 -2
- package/inputs/ImageInput/index.js +49 -12
- package/inputs/ImageInput/index.js.map +2 -2
- package/inputs/Input/Input.stories.d.ts +5 -0
- package/inputs/Input/__stories__/AFM.d.ts +1 -1
- package/inputs/Input/__stories__/AMKA.d.ts +3 -0
- package/inputs/Input/__stories__/Boolean.d.ts +1 -1
- package/inputs/Input/__stories__/Email.d.ts +3 -0
- package/inputs/Input/__stories__/IBAN.d.ts +1 -1
- package/inputs/Input/__stories__/Integer.d.ts +1 -1
- package/inputs/Input/__stories__/LandlineNumber.d.ts +1 -1
- package/inputs/Input/__stories__/MobilePhone.d.ts +1 -1
- package/inputs/Input/__stories__/PhoneNumber.d.ts +1 -1
- package/inputs/Input/__stories__/PostalCode.d.ts +1 -1
- package/inputs/Input/__stories__/String.d.ts +1 -1
- package/inputs/Input/__stories__/StringWithTrimValidation.d.ts +3 -0
- package/inputs/Input/__stories__/TextWithLimit.d.ts +1 -1
- package/inputs/Input/index.d.ts +4 -3
- package/inputs/Input/index.js +55 -49
- 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 -3
- 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.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 +5 -5
- package/inputs/Radio/index.js +6 -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 +5 -4
- package/inputs/Select/index.js +13 -3
- package/inputs/Select/index.js.map +2 -2
- package/{Field/utils → inputs/registry}/index.js +10 -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 +80 -70
- package/package.json +8 -8
- package/registry/index.js +129 -108
- package/src/Field/ErrorGroup.tsx +84 -0
- package/src/Field/FieldBase.tsx +40 -26
- package/src/Field/FieldBaseContainer.tsx +70 -46
- package/src/Field/FieldConditional.tsx +7 -3
- package/src/Field/doc.mdx +202 -1
- package/src/Field/index.tsx +32 -37
- package/src/Field/types.tsx +53 -41
- package/src/Field/utils/evaluateFieldWithConditions.ts +5 -2
- package/src/Field/utils/resolveField.ts +58 -0
- package/src/Field/utils/useField.ts +17 -3
- 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 +299 -0
- package/src/FieldArray/__stories__/CardsWithError.tsx +124 -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/__tests__/fieldset-multiplicity.spec.tsx +271 -0
- package/src/FieldArray/__tests__/multiplicity-attachment.spec.tsx +280 -0
- package/src/FieldArray/__tests__/multiplicity-required.spec.tsx +131 -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 +78 -61
- package/src/FieldObject/index.tsx +43 -30
- 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 +226 -90
- package/src/FormBuilder/interaction.test.tsx +40 -0
- package/src/FormBuilder/scenarios.test.tsx +1003 -130
- package/src/FormContext.tsx +7 -3
- 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 +18 -24
- package/src/MultiplicityField/doc.mdx +101 -83
- package/src/MultiplicityField/index.test.tsx +4 -0
- package/src/MultiplicityField/index.tsx +7 -2
- package/src/MultiplicityField/types.ts +6 -3
- package/src/Questions/Questions.stories.js +3 -0
- package/src/Questions/Questions.tsx +6 -6
- package/src/Questions/QuestionsContext.tsx +1 -1
- package/src/Questions/Step/Step.tsx +1 -1
- package/src/Questions/Step/StepArrayReview.tsx +3 -3
- 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 +14 -2
- 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 +3 -11
- package/src/inputs/AutoCompleteInput/__stories__/Multiple.tsx +2 -8
- package/src/inputs/AutoCompleteInput/index.test.tsx +4 -0
- package/src/inputs/AutoCompleteInput/index.tsx +8 -11
- 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 +96 -90
- package/src/inputs/DateInput/DateInput.stories.js +7 -0
- package/src/inputs/DateInput/__stories__/Default.tsx +8 -13
- package/src/inputs/DateInput/__stories__/WithDefaultValue.tsx +26 -0
- package/src/inputs/DateInput/__stories__/WithInitialValue.tsx +28 -0
- package/src/inputs/DateInput/__stories__/WithWrongDefaultValue.tsx +26 -0
- package/src/inputs/DateInput/__stories__/WithWrongInitialValue.tsx +28 -0
- package/src/inputs/DateInput/index.test.tsx +20 -0
- package/src/inputs/DateInput/index.tsx +71 -23
- 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 +246 -0
- package/src/inputs/FileInput/FileInput.stories.js +4 -0
- package/src/inputs/FileInput/__stories__/Default.tsx +1 -1
- package/src/inputs/FileInput/__stories__/WithBorderAndLink.tsx +34 -0
- package/src/inputs/FileInput/index.test.tsx +8 -0
- package/src/inputs/FileInput/index.tsx +105 -37
- package/src/inputs/ImageInput/ImageInput.stories.js +5 -2
- package/src/inputs/ImageInput/__stories__/Default.tsx +1 -1
- package/src/inputs/ImageInput/__stories__/MaxSize.tsx +5 -4
- package/src/inputs/ImageInput/__stories__/{WithInvalidImageSize.tsx → WithInitialValues.tsx} +12 -3
- package/src/inputs/ImageInput/__stories__/WithInvalidImageDimension.tsx +1 -1
- package/src/inputs/ImageInput/__stories__/logo.d.ts +4 -0
- package/src/inputs/ImageInput/__stories__/logo.png +0 -0
- package/src/inputs/ImageInput/index.test.tsx +8 -4
- package/src/inputs/ImageInput/index.tsx +98 -43
- 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/index.test.tsx +16 -0
- package/src/inputs/Input/index.tsx +81 -70
- 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 -4
- 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 +45 -34
- 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 +31 -22
- 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 +20 -8
- package/src/{Field/utils/index.ts → inputs/registry.ts} +11 -1
- package/src/lazy.js +80 -67
- package/src/registry.js +122 -102
- package/src/types.tsx +16 -7
- package/src/utils.ts +32 -10
- package/src/validators/index.ts +110 -34
- 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 +222 -0
- package/src/validators/utils/email.ts +11 -0
- package/src/validators/utils/file.ts +35 -19
- package/src/validators/utils/iban.ts +2 -2
- package/src/validators/utils/image.ts +2 -2
- package/src/validators/utils/index.ts +7 -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 +3 -3
- package/src/validators/utils/postal_code.ts +3 -3
- package/src/validators/utils/text_limit.ts +2 -2
- package/src/validators/utils/uuid4.ts +2 -1
- package/src/validators/validators.spec.ts +3 -3
- package/types.d.ts +12 -6
- package/types.js.map +1 -1
- package/utils/index.js +22 -7
- package/utils.d.ts +3 -1
- package/utils.js.map +2 -2
- package/validators/index.d.ts +6 -6
- package/validators/index.js +61 -25
- 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 +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/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 +4 -2
- package/validators/utils/index.js +5 -1
- package/validators/utils/index.js.map +2 -2
- package/validators/utils/int/index.js +1 -1
- package/validators/utils/int.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 +3 -3
- package/validators/utils/phone.js.map +2 -2
- package/validators/utils/postal_code.d.ts +3 -3
- 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/validators/utils/uuid4.js.map +2 -2
- package/Field/utils/calculateField/index.js +0 -27
- package/Field/utils/calculateField/package.json +0 -6
- 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/FieldArray.stories/index.js +0 -14
- package/FieldArray/FieldArray.stories/package.json +0 -6
- 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/FormBuilder/index.test.d.ts +0 -1
- package/FormBuilder/scenarios.test.d.ts +0 -88
- 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/MultiplicityField/index.test.d.ts +0 -1
- 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/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/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.js.map +0 -7
- package/cjs/FormBuilder/FormBuilder.stories.js.map +0 -7
- package/cjs/FormBuilder/__stories__/Default.js.map +0 -7
- package/cjs/MultiplicityField/MultiplicityField.stories/index.js +0 -60
- package/cjs/MultiplicityField/MultiplicityField.stories.js.map +0 -7
- package/cjs/MultiplicityField/__stories__/Default/index.js +0 -133
- package/cjs/MultiplicityField/__stories__/Default.js.map +0 -7
- package/cjs/MultiplicityField/__stories__/PreviewDisplay/index.js +0 -86
- package/cjs/MultiplicityField/__stories__/PreviewDisplay.js.map +0 -7
- package/cjs/MultiplicityField/__stories__/WithExactLength/index.js +0 -130
- package/cjs/MultiplicityField/__stories__/WithExactLength.js.map +0 -7
- package/cjs/MultiplicityField/__stories__/WithMaxLength/index.js +0 -133
- package/cjs/MultiplicityField/__stories__/WithMaxLength.js.map +0 -7
- package/cjs/MultiplicityField/__stories__/WithMinAndMaxLength/index.js +0 -134
- package/cjs/MultiplicityField/__stories__/WithMinAndMaxLength.js.map +0 -7
- package/cjs/MultiplicityField/__stories__/WithMinLength/index.js +0 -133
- package/cjs/MultiplicityField/__stories__/WithMinLength.js.map +0 -7
- package/cjs/Questions/Questions.stories/index.js +0 -45
- package/cjs/Questions/Questions.stories.js.map +0 -7
- package/cjs/Questions/__stories__/Default/index.js +0 -136
- package/cjs/Questions/__stories__/Default.js.map +0 -7
- package/cjs/inputs/AutoCompleteInput/AutoComplete.stories/index.js +0 -48
- package/cjs/inputs/AutoCompleteInput/AutoComplete.stories.js.map +0 -7
- package/cjs/inputs/AutoCompleteInput/__stories__/Default/index.js +0 -83
- package/cjs/inputs/AutoCompleteInput/__stories__/Default.js.map +0 -7
- package/cjs/inputs/AutoCompleteInput/__stories__/Multiple/index.js +0 -83
- package/cjs/inputs/AutoCompleteInput/__stories__/Multiple.js.map +0 -7
- package/cjs/inputs/Checkboxes/Checkboxes.stories/index.js +0 -51
- package/cjs/inputs/Checkboxes/Checkboxes.stories.js.map +0 -7
- package/cjs/inputs/Checkboxes/__stories__/Conditional/index.js +0 -133
- package/cjs/inputs/Checkboxes/__stories__/Conditional.js.map +0 -7
- package/cjs/inputs/Checkboxes/__stories__/Default/index.js +0 -77
- package/cjs/inputs/Checkboxes/__stories__/Default.js.map +0 -7
- package/cjs/inputs/Checkboxes/__stories__/WithDivider/index.js +0 -78
- package/cjs/inputs/Checkboxes/__stories__/WithDivider.js.map +0 -7
- package/cjs/inputs/DateInput/DateInput.stories/index.js +0 -45
- package/cjs/inputs/DateInput/DateInput.stories.js.map +0 -7
- package/cjs/inputs/DateInput/__stories__/Default/index.js +0 -61
- package/cjs/inputs/DateInput/__stories__/Default.js.map +0 -7
- package/cjs/inputs/FileInput/FileInput.stories/index.js +0 -45
- package/cjs/inputs/FileInput/FileInput.stories.js.map +0 -7
- package/cjs/inputs/FileInput/__stories__/Default/index.js +0 -61
- package/cjs/inputs/FileInput/__stories__/Default.js.map +0 -7
- package/cjs/inputs/ImageInput/ImageInput.stories/index.js +0 -51
- package/cjs/inputs/ImageInput/ImageInput.stories.js.map +0 -7
- package/cjs/inputs/ImageInput/__stories__/Default/index.js +0 -63
- package/cjs/inputs/ImageInput/__stories__/Default.js.map +0 -7
- package/cjs/inputs/ImageInput/__stories__/MaxSize/index.js +0 -69
- package/cjs/inputs/ImageInput/__stories__/MaxSize.js.map +0 -7
- package/cjs/inputs/ImageInput/__stories__/WithInvalidImageDimension/index.js +0 -72
- package/cjs/inputs/ImageInput/__stories__/WithInvalidImageDimension.js.map +0 -7
- package/cjs/inputs/ImageInput/__stories__/WithInvalidImageSize/index.js +0 -68
- package/cjs/inputs/ImageInput/__stories__/WithInvalidImageSize.js.map +0 -7
- package/cjs/inputs/Input/Input.stories/index.js +0 -72
- package/cjs/inputs/Input/Input.stories.js.map +0 -7
- package/cjs/inputs/Input/__stories__/AFM/index.js +0 -63
- package/cjs/inputs/Input/__stories__/AFM.js.map +0 -7
- package/cjs/inputs/Input/__stories__/Boolean/index.js +0 -64
- package/cjs/inputs/Input/__stories__/Boolean.js.map +0 -7
- package/cjs/inputs/Input/__stories__/IBAN/index.js +0 -64
- package/cjs/inputs/Input/__stories__/IBAN.js.map +0 -7
- package/cjs/inputs/Input/__stories__/Integer/index.js +0 -78
- package/cjs/inputs/Input/__stories__/Integer.js.map +0 -7
- package/cjs/inputs/Input/__stories__/LandlineNumber/index.js +0 -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/cjs/inputs/inputsScenarios/index.js +0 -539
- package/cjs/inputs/inputsScenarios.js.map +0 -7
- package/cjs/locales/el/index.js +0 -35
- package/cjs/locales/el.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/AutoCompleteInput/index.test.d.ts +0 -1
- package/inputs/Checkboxes/Checkboxes.stories/index.js +0 -16
- 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/Checkboxes/index.test.d.ts +0 -1
- package/inputs/DateInput/DateInput.stories/index.js +0 -12
- 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/DateInput/index.test.d.ts +0 -1
- 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/FileInput/index.test.d.ts +0 -1
- package/inputs/ImageInput/ImageInput.stories/index.js +0 -16
- package/inputs/ImageInput/ImageInput.stories/package.json +0 -6
- package/inputs/ImageInput/ImageInput.stories.js.map +0 -7
- package/inputs/ImageInput/__stories__/Default/index.js +0 -30
- package/inputs/ImageInput/__stories__/Default/package.json +0 -6
- package/inputs/ImageInput/__stories__/Default.js.map +0 -7
- package/inputs/ImageInput/__stories__/MaxSize/index.js +0 -36
- package/inputs/ImageInput/__stories__/MaxSize/package.json +0 -6
- package/inputs/ImageInput/__stories__/MaxSize.js.map +0 -7
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension/index.js +0 -39
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension/package.json +0 -6
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension.js.map +0 -7
- package/inputs/ImageInput/__stories__/WithInvalidImageSize/index.js +0 -35
- package/inputs/ImageInput/__stories__/WithInvalidImageSize/package.json +0 -6
- package/inputs/ImageInput/__stories__/WithInvalidImageSize.d.ts +0 -3
- package/inputs/ImageInput/__stories__/WithInvalidImageSize.js.map +0 -7
- package/inputs/ImageInput/index.test.d.ts +0 -1
- package/inputs/Input/Input.stories/index.js +0 -30
- package/inputs/Input/Input.stories/package.json +0 -6
- 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/index.test.d.ts +0 -1
- 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/Label/index.test.d.ts +0 -1
- 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/OtpInput/index.test.d.ts +0 -1
- 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/Radio/index.test.d.ts +0 -1
- 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/inputs/Select/index.test.d.ts +0 -1
- package/inputs/inputsScenarios/index.js +0 -505
- package/inputs/inputsScenarios.d.ts +0 -296
- package/inputs/inputsScenarios.js.map +0 -7
- package/lazy.d.ts +0 -80
- package/lazy.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/registry.d.ts +0 -71
- package/registry.js.map +0 -7
- package/src/Field/utils/calculateField.ts +0 -49
- package/src/inputs/Input/inputsInputScenarios.ts +0 -405
- package/src/inputs/inputsScenarios.ts +0 -502
- package/src/locales/el.ts +0 -3
- /package/{FieldArray/index.test.d.ts → hooks/__tests__/utils.spec.d.ts} +0 -0
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,13 +39,32 @@ 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 = {}) =>
|
|
43
65
|
async (values, context, options) => {
|
|
44
66
|
try {
|
|
45
67
|
if (schemaOptions.context && process.env.NODE_ENV === 'development') {
|
|
46
|
-
// eslint-disable-next-line no-console
|
|
47
68
|
console.warn(
|
|
48
69
|
"You should not used the yup options context. Please, use the 'useForm' context object instead"
|
|
49
70
|
);
|
|
@@ -52,11 +73,12 @@ export const yupResolver =
|
|
|
52
73
|
const result = await schema[
|
|
53
74
|
resolverOptions.mode === 'sync' ? 'validateSync' : 'validate'
|
|
54
75
|
](
|
|
55
|
-
values,
|
|
76
|
+
flattenObject(values),
|
|
56
77
|
Object.assign({ abortEarly: false }, schemaOptions, { context })
|
|
57
78
|
);
|
|
58
79
|
|
|
59
|
-
options.shouldUseNativeValidation
|
|
80
|
+
if (options.shouldUseNativeValidation)
|
|
81
|
+
validateFieldsNatively({}, options);
|
|
60
82
|
|
|
61
83
|
return {
|
|
62
84
|
values: resolverOptions.rawValues ? values : result,
|
|
@@ -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,
|
|
@@ -23,17 +25,23 @@ import {
|
|
|
23
25
|
DATE_VALIDATOR,
|
|
24
26
|
LATER_THAN_VALIDATOR,
|
|
25
27
|
EARLIER_THAN_VALIDATOR,
|
|
28
|
+
DATETIME_VALIDATOR,
|
|
29
|
+
LATER_THAN_DATETIME_VALIDATOR,
|
|
30
|
+
EARLIER_THAN_DATETIME_VALIDATOR,
|
|
26
31
|
} from '@digigov/form/validators/utils';
|
|
32
|
+
import { EMAIL_VALIDATOR } from '@digigov/form/validators/utils/email';
|
|
27
33
|
import { INT_VALIDATOR } from '@digigov/form/validators/utils/int';
|
|
28
34
|
import { NUMBER_VALIDATOR } from '@digigov/form/validators/utils/number';
|
|
29
35
|
|
|
30
|
-
export const getYUPTypeMap = (
|
|
36
|
+
export const getYUPTypeMap = (
|
|
37
|
+
validatorRegistry?: Record<string, any>
|
|
38
|
+
): Record<string, any> => {
|
|
31
39
|
const yupTypeMap = {
|
|
32
40
|
file: (field): MixedSchema => {
|
|
33
41
|
return yup
|
|
34
42
|
.mixed()
|
|
35
43
|
.transform((value) => {
|
|
36
|
-
if (!value.length) {
|
|
44
|
+
if (!value || value.length === 0) {
|
|
37
45
|
return null;
|
|
38
46
|
}
|
|
39
47
|
return value;
|
|
@@ -41,8 +49,28 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
41
49
|
.nullable()
|
|
42
50
|
.test(FILE_MAX_SIZE_VALIDATOR(field));
|
|
43
51
|
},
|
|
44
|
-
string: yup.
|
|
45
|
-
|
|
52
|
+
string: (field): yup.StringSchema => {
|
|
53
|
+
if (field.trim) {
|
|
54
|
+
return yup.string().trim();
|
|
55
|
+
} else {
|
|
56
|
+
return yup.string();
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
boolean: (): yup.BooleanSchema<
|
|
60
|
+
boolean | null | undefined,
|
|
61
|
+
AnyObject,
|
|
62
|
+
boolean | null | undefined
|
|
63
|
+
> => {
|
|
64
|
+
return yup
|
|
65
|
+
.boolean()
|
|
66
|
+
.nullable()
|
|
67
|
+
.transform((value) => {
|
|
68
|
+
if (value === '' || typeof value === 'string') return null;
|
|
69
|
+
if (typeof value === 'boolean') return value;
|
|
70
|
+
if (value === 0 || value === 1) return Boolean(value);
|
|
71
|
+
return value;
|
|
72
|
+
});
|
|
73
|
+
},
|
|
46
74
|
object: (
|
|
47
75
|
field
|
|
48
76
|
):
|
|
@@ -58,10 +86,13 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
58
86
|
if (typeof field.extra.of === 'object') {
|
|
59
87
|
// else if the field is an object then it is a scalar type
|
|
60
88
|
// eg. number, string etc.
|
|
89
|
+
if (field.required) {
|
|
90
|
+
field.extra.min = 1;
|
|
91
|
+
}
|
|
61
92
|
let arrayValidator = yup
|
|
62
93
|
.array()
|
|
63
|
-
.
|
|
64
|
-
.
|
|
94
|
+
.nullable()
|
|
95
|
+
.of(yupTypeMap[field.extra.of.type](field.extra.of));
|
|
65
96
|
if (field.extra.length)
|
|
66
97
|
arrayValidator = arrayValidator.length(field.extra.length, {
|
|
67
98
|
key: 'form.error.array.length',
|
|
@@ -74,12 +105,14 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
74
105
|
key: 'form.error.array.min',
|
|
75
106
|
context: {
|
|
76
107
|
min: field.extra.min,
|
|
108
|
+
max: field.extra.max || undefined,
|
|
77
109
|
},
|
|
78
110
|
});
|
|
79
111
|
if (field.extra.max)
|
|
80
112
|
arrayValidator = arrayValidator.max(field.extra.max, {
|
|
81
113
|
key: 'form.error.array.max',
|
|
82
114
|
context: {
|
|
115
|
+
min: field.extra.min || undefined,
|
|
83
116
|
max: field.extra.max,
|
|
84
117
|
},
|
|
85
118
|
});
|
|
@@ -94,24 +127,43 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
94
127
|
number: (): MixedSchema =>
|
|
95
128
|
yup
|
|
96
129
|
.mixed()
|
|
97
|
-
.transform((_, val) => (val !== '' ? Number(val) :
|
|
130
|
+
.transform((_, val) => (val !== '' ? Number(val) : undefined))
|
|
98
131
|
.test(NUMBER_VALIDATOR()),
|
|
99
132
|
int: (): MixedSchema =>
|
|
100
133
|
yup
|
|
101
134
|
.mixed()
|
|
102
|
-
.transform((_, val) => (val !== '' ? Number(val) :
|
|
135
|
+
.transform((_, val) => (val !== '' ? Number(val) : undefined))
|
|
103
136
|
.test(NUMBER_VALIDATOR())
|
|
104
137
|
.test(INT_VALIDATOR()),
|
|
105
|
-
email: (): yup.StringSchema =>
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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),
|
|
154
|
+
iban: (field): yup.StringSchema =>
|
|
155
|
+
field.trim
|
|
156
|
+
? yup.string().trim().test(IBAN_VALIDATOR(field))
|
|
157
|
+
: yup.string().trim().test(IBAN_VALIDATOR(field)),
|
|
158
|
+
otp: (field): yup.StringSchema =>
|
|
159
|
+
yup.string().trim().test(OTP_VALIDATOR(field)),
|
|
110
160
|
text: (field): yup.StringSchema => {
|
|
111
161
|
if (field?.extra?.limit?.max || !!field?.extra?.limit?.min) {
|
|
112
|
-
return
|
|
162
|
+
return field.trim
|
|
163
|
+
? yup.string().trim().test(TEXT_LIMIT_VALIDATOR(field))
|
|
164
|
+
: yup.string().test(TEXT_LIMIT_VALIDATOR(field));
|
|
113
165
|
} else {
|
|
114
|
-
return yup.string();
|
|
166
|
+
return field.trim ? yup.string().trim() : yup.string();
|
|
115
167
|
}
|
|
116
168
|
},
|
|
117
169
|
image: (field): MixedSchema => {
|
|
@@ -128,11 +180,17 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
128
180
|
.test(IMAGE_DIMENSION_VALIDATOR(field));
|
|
129
181
|
},
|
|
130
182
|
postal_code: (field): yup.StringSchema =>
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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),
|
|
134
190
|
phone_number: (field): yup.StringSchema =>
|
|
135
|
-
|
|
191
|
+
field.trim
|
|
192
|
+
? yup.string().trim().test(PHONE_NUMBER_VALIDATOR(field))
|
|
193
|
+
: yup.string().test(PHONE_NUMBER_VALIDATOR(field)),
|
|
136
194
|
'choice:multiple': (): yup.ArraySchema<
|
|
137
195
|
yup.StringSchema<string | undefined, AnyObject, string | undefined>,
|
|
138
196
|
AnyObject,
|
|
@@ -144,16 +202,34 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
144
202
|
AnyObject,
|
|
145
203
|
string | null | undefined
|
|
146
204
|
> => yup.string().nullable(),
|
|
147
|
-
date: (
|
|
205
|
+
date: (
|
|
206
|
+
field
|
|
207
|
+
): yup.StringSchema<
|
|
208
|
+
string | null | undefined,
|
|
209
|
+
AnyObject,
|
|
210
|
+
string | null | undefined
|
|
211
|
+
> => {
|
|
212
|
+
let schema = yup.string().nullable();
|
|
148
213
|
if (field?.extra?.min) {
|
|
149
|
-
|
|
214
|
+
schema = schema.test(LATER_THAN_VALIDATOR(field));
|
|
150
215
|
}
|
|
151
216
|
if (field?.extra?.max) {
|
|
152
|
-
|
|
217
|
+
schema = schema.test(EARLIER_THAN_VALIDATOR(field));
|
|
153
218
|
} else {
|
|
154
|
-
|
|
219
|
+
schema = schema.test(DATE_VALIDATOR);
|
|
220
|
+
}
|
|
221
|
+
return schema;
|
|
222
|
+
},
|
|
223
|
+
datetime: (field): yup.StringSchema => {
|
|
224
|
+
if (field?.extra?.min) {
|
|
225
|
+
return yup.string().test(LATER_THAN_DATETIME_VALIDATOR(field));
|
|
226
|
+
}
|
|
227
|
+
if (field?.extra?.max) {
|
|
228
|
+
return yup.string().test(EARLIER_THAN_DATETIME_VALIDATOR(field));
|
|
155
229
|
}
|
|
230
|
+
return yup.string().test(DATETIME_VALIDATOR);
|
|
156
231
|
},
|
|
232
|
+
...validatorRegistry,
|
|
157
233
|
};
|
|
158
234
|
return yupTypeMap;
|
|
159
235
|
};
|
|
@@ -165,7 +241,7 @@ export function useValidationSchema(
|
|
|
165
241
|
validatorRegistry?: Record<string, ValidatorSchema[]>
|
|
166
242
|
): Lazy<any, unknown> | AnyObjectSchema | void {
|
|
167
243
|
return useMemo(() => {
|
|
168
|
-
const yupTypeMap = getYUPTypeMap();
|
|
244
|
+
const yupTypeMap = getYUPTypeMap(validatorRegistry);
|
|
169
245
|
return getYupObjectShape(fields, yupTypeMap, validatorRegistry);
|
|
170
|
-
}, []);
|
|
246
|
+
}, [fields, validatorRegistry]);
|
|
171
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) {
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
3
|
+
import type { FieldSpec } from '@digigov/form/types';
|
|
4
|
+
import type { 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
|
+
};
|
|
@@ -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
|
+
};
|