@digigov/form 2.0.0-cbc56209 → 2.0.0-d4fe516b
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/{Questions/index.spec → 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 +112 -76
- package/Field/FieldBase.js.map +7 -0
- package/Field/FieldBaseContainer/index.js +30 -37
- package/Field/FieldBaseContainer.js.map +7 -0
- package/Field/FieldConditional/index.js +79 -53
- package/Field/FieldConditional.js.map +7 -0
- package/Field/index.js +107 -63
- package/Field/index.js.map +7 -0
- package/Field/types/index.js +1 -1
- package/Field/types.d.ts +44 -5
- package/Field/types.js.map +7 -0
- package/Field/utils/calculateField/index.js +27 -0
- package/{FieldArray/FieldArray.stories → Field/utils/calculateField}/package.json +1 -1
- package/Field/utils/calculateField.d.ts +2 -0
- package/Field/utils/calculateField.js.map +7 -0
- package/Field/utils/evaluateFieldWithConditions/index.js +26 -0
- package/{inputs/DateInput/__stories__/Default → Field/utils/evaluateFieldWithConditions}/package.json +1 -1
- package/Field/utils/evaluateFieldWithConditions.d.ts +2 -0
- package/Field/utils/evaluateFieldWithConditions.js.map +7 -0
- package/Field/utils/index.d.ts +4 -0
- package/Field/utils/index.js +47 -116
- package/Field/utils/index.js.map +7 -0
- package/Field/utils/useField/index.js +57 -0
- package/{FormBuilder/FormBuilder → Field/utils/useField}/package.json +1 -1
- package/Field/utils/useField.d.ts +2 -0
- package/Field/utils/useField.js.map +7 -0
- package/FieldArray/FieldArray.stories.d.ts +2 -2
- package/FieldArray/FormDialog/index.js +280 -0
- package/{validators/validators.spec → FieldArray/FormDialog}/package.json +1 -1
- package/FieldArray/FormDialog.d.ts +53 -0
- package/FieldArray/FormDialog.js.map +7 -0
- package/FieldArray/__stories__/Default.d.ts +2 -2
- package/FieldArray/__stories__/WithExactLength.d.ts +2 -2
- package/FieldArray/index.d.ts +6 -0
- package/FieldArray/index.js +108 -59
- package/FieldArray/index.js.map +7 -0
- package/FieldArray/index.test.d.ts +1 -0
- package/FieldObject/index.d.ts +5 -0
- package/FieldObject/index.js +75 -52
- package/FieldObject/index.js.map +7 -0
- package/Fieldset/FieldsetWithContext/index.js +27 -31
- package/Fieldset/FieldsetWithContext.js.map +7 -0
- package/Fieldset/index.d.ts +1 -1
- package/Fieldset/index.js +27 -29
- package/Fieldset/index.js.map +7 -0
- package/Fieldset/types/index.js +1 -1
- package/Fieldset/types.d.ts +3 -2
- package/Fieldset/types.js.map +7 -0
- package/FormBuilder/FormBuilder.stories.d.ts +3 -1
- package/FormBuilder/__stories__/AutoErrorGrouping.d.ts +3 -0
- package/FormBuilder/__stories__/Default.d.ts +2 -2
- package/FormBuilder/__stories__/ErrorGrouping.d.ts +3 -0
- package/FormBuilder/index.d.ts +8 -1
- package/FormBuilder/index.js +237 -2
- package/FormBuilder/index.js.map +7 -0
- package/FormBuilder/index.test.d.ts +1 -0
- package/FormBuilder/interaction.test.d.ts +1 -0
- package/FormBuilder/scenarios.test.d.ts +88 -0
- package/FormContext/index.js +7 -3
- package/FormContext.js.map +7 -0
- package/MultiplicityField/MultiplicityField.stories.d.ts +6 -6
- package/MultiplicityField/__stories__/Default.d.ts +2 -2
- package/MultiplicityField/__stories__/PreviewDisplay.d.ts +2 -2
- package/MultiplicityField/__stories__/WithExactLength.d.ts +2 -2
- package/MultiplicityField/__stories__/WithMaxLength.d.ts +2 -2
- package/MultiplicityField/__stories__/WithMinAndMaxLength.d.ts +2 -2
- package/MultiplicityField/__stories__/WithMinLength.d.ts +2 -2
- package/MultiplicityField/add-objects/index.js +137 -132
- package/MultiplicityField/add-objects.d.ts +2 -1
- package/MultiplicityField/add-objects.js.map +7 -0
- package/MultiplicityField/index.d.ts +2 -19
- package/MultiplicityField/index.js +114 -106
- package/MultiplicityField/index.js.map +7 -0
- package/MultiplicityField/index.test.d.ts +1 -0
- package/MultiplicityField/types/index.js +1 -0
- package/MultiplicityField/types/package.json +6 -0
- package/MultiplicityField/types.d.ts +18 -0
- package/MultiplicityField/types.js.map +7 -0
- package/Questions/Questions/index.js +48 -56
- package/Questions/Questions.js.map +7 -0
- package/Questions/Questions.stories.d.ts +1 -1
- package/Questions/QuestionsContext/index.js +9 -9
- package/Questions/QuestionsContext.d.ts +0 -1
- package/Questions/QuestionsContext.js.map +7 -0
- package/Questions/Step/ReviewStep/index.js +35 -47
- package/Questions/Step/ReviewStep.js.map +7 -0
- package/Questions/Step/Step/index.js +39 -47
- package/Questions/Step/Step.js.map +7 -0
- package/Questions/Step/StepArrayReview/index.js +41 -45
- package/Questions/Step/StepArrayReview.js.map +7 -0
- package/Questions/Step/StepContext/index.js +15 -19
- package/Questions/Step/StepContext.d.ts +0 -1
- package/Questions/Step/StepContext.js.map +7 -0
- package/Questions/Step/StepDescription/index.js +22 -22
- package/Questions/Step/StepDescription.js.map +7 -0
- package/Questions/Step/StepForm/index.js +33 -43
- package/Questions/Step/StepForm.js.map +7 -0
- package/Questions/Step/StepQuote/index.js +10 -9
- package/Questions/Step/StepQuote.js.map +7 -0
- package/Questions/Step/StepTitle/index.js +41 -38
- package/Questions/Step/StepTitle.d.ts +2 -1
- package/Questions/Step/StepTitle.js.map +7 -0
- package/Questions/Step/getAddMoreFields/index.js +28 -20
- package/Questions/Step/getAddMoreFields.js.map +7 -0
- package/Questions/Step/index.d.ts +0 -1
- package/Questions/Step/index.js +16 -13
- package/Questions/Step/index.js.map +7 -0
- package/Questions/Step/types/index.js +1 -1
- package/Questions/Step/types.d.ts +1 -0
- package/Questions/Step/types.js.map +7 -0
- package/Questions/__stories__/Default.d.ts +2 -2
- package/Questions/getNextStep/index.js +12 -10
- package/Questions/getNextStep.js.map +7 -0
- package/Questions/index.js +7 -3
- package/Questions/index.js.map +7 -0
- package/Questions/index.test.d.ts +1 -0
- package/Questions/types/index.js +1 -1
- package/Questions/types.d.ts +1 -0
- package/Questions/types.js.map +7 -0
- package/cjs/Field/ErrorGroup/index.js +82 -0
- package/cjs/Field/ErrorGroup.js.map +7 -0
- package/cjs/Field/FieldBase/index.js +144 -82
- package/cjs/Field/FieldBase.js.map +7 -0
- package/cjs/Field/FieldBaseContainer/index.js +62 -43
- package/cjs/Field/FieldBaseContainer.js.map +7 -0
- package/cjs/Field/FieldConditional/index.js +111 -59
- package/cjs/Field/FieldConditional.js.map +7 -0
- package/cjs/Field/index.js +136 -72
- package/cjs/Field/index.js.map +7 -0
- package/cjs/Field/types/index.js +16 -5
- package/cjs/Field/types.js.map +7 -0
- package/cjs/Field/utils/calculateField/index.js +50 -0
- package/cjs/Field/utils/calculateField.js.map +7 -0
- package/cjs/Field/utils/evaluateFieldWithConditions/index.js +49 -0
- package/cjs/Field/utils/evaluateFieldWithConditions.js.map +7 -0
- package/cjs/Field/utils/index.js +91 -139
- package/cjs/Field/utils/index.js.map +7 -0
- package/cjs/Field/utils/useField/index.js +80 -0
- package/cjs/Field/utils/useField.js.map +7 -0
- package/cjs/FieldArray/FormDialog/index.js +302 -0
- package/cjs/FieldArray/FormDialog.js.map +7 -0
- package/cjs/FieldArray/index.js +140 -65
- package/cjs/FieldArray/index.js.map +7 -0
- package/cjs/FieldObject/index.js +104 -61
- package/cjs/FieldObject/index.js.map +7 -0
- package/cjs/Fieldset/FieldsetWithContext/index.js +54 -40
- package/cjs/Fieldset/FieldsetWithContext.js.map +7 -0
- package/cjs/Fieldset/index.js +61 -39
- package/cjs/Fieldset/index.js.map +7 -0
- package/cjs/Fieldset/types/index.js +16 -5
- package/cjs/Fieldset/types.js.map +7 -0
- package/cjs/FormBuilder/index.js +273 -8
- package/cjs/FormBuilder/index.js.map +7 -0
- package/cjs/FormContext/index.js +29 -8
- package/cjs/FormContext.js.map +7 -0
- package/cjs/MultiplicityField/add-objects/index.js +164 -138
- package/cjs/MultiplicityField/add-objects.js.map +7 -0
- package/cjs/MultiplicityField/index.js +142 -115
- package/cjs/MultiplicityField/index.js.map +7 -0
- package/cjs/MultiplicityField/types/index.js +16 -0
- package/cjs/MultiplicityField/types.js.map +7 -0
- package/cjs/Questions/Questions/index.js +80 -65
- package/cjs/Questions/Questions.js.map +7 -0
- package/cjs/Questions/QuestionsContext/index.js +31 -14
- package/cjs/Questions/QuestionsContext.js.map +7 -0
- package/cjs/Questions/Step/ReviewStep/index.js +61 -56
- package/cjs/Questions/Step/ReviewStep.js.map +7 -0
- package/cjs/Questions/Step/Step/index.js +71 -56
- package/cjs/Questions/Step/Step.js.map +7 -0
- package/cjs/Questions/Step/StepArrayReview/index.js +65 -54
- package/cjs/Questions/Step/StepArrayReview.js.map +7 -0
- package/cjs/Questions/Step/StepContext/index.js +37 -24
- package/cjs/Questions/Step/StepContext.js.map +7 -0
- package/cjs/Questions/Step/StepDescription/index.js +55 -31
- package/cjs/Questions/Step/StepDescription.js.map +7 -0
- package/cjs/Questions/Step/StepForm/index.js +65 -52
- package/cjs/Questions/Step/StepForm.js.map +7 -0
- package/cjs/Questions/Step/StepQuote/index.js +42 -15
- package/cjs/Questions/Step/StepQuote.js.map +7 -0
- package/cjs/Questions/Step/StepTitle/index.js +72 -47
- package/cjs/Questions/Step/StepTitle.js.map +7 -0
- package/cjs/Questions/Step/getAddMoreFields/index.js +50 -25
- package/cjs/Questions/Step/getAddMoreFields.js.map +7 -0
- package/cjs/Questions/Step/index.js +59 -143
- package/cjs/Questions/Step/index.js.map +7 -0
- package/cjs/Questions/Step/types/index.js +16 -5
- package/cjs/Questions/Step/types.js.map +7 -0
- package/cjs/Questions/getNextStep/index.js +33 -14
- package/cjs/Questions/getNextStep.js.map +7 -0
- package/cjs/Questions/index.js +29 -19
- package/cjs/Questions/index.js.map +7 -0
- package/cjs/Questions/types/index.js +16 -5
- package/cjs/Questions/types.js.map +7 -0
- package/cjs/index.js +47 -20
- package/cjs/index.js.map +7 -0
- package/cjs/inputs/AutoCompleteInput/index.js +92 -46
- package/cjs/inputs/AutoCompleteInput/index.js.map +7 -0
- package/cjs/inputs/Checkboxes/index.js +101 -96
- package/cjs/inputs/Checkboxes/index.js.map +7 -0
- package/cjs/inputs/DateInput/index.js +121 -109
- package/cjs/inputs/DateInput/index.js.map +7 -0
- package/cjs/inputs/DateTimeInput/index.js +206 -0
- package/cjs/inputs/DateTimeInput/index.js.map +7 -0
- package/cjs/inputs/FileInput/index.js +75 -63
- package/cjs/inputs/FileInput/index.js.map +7 -0
- package/cjs/inputs/ImageInput/index.js +95 -83
- package/cjs/inputs/ImageInput/index.js.map +7 -0
- package/cjs/inputs/Input/index.js +105 -71
- package/cjs/inputs/Input/index.js.map +7 -0
- package/cjs/inputs/Input/inputsInputScenarios/index.js +439 -0
- package/cjs/inputs/Input/inputsInputScenarios.js.map +7 -0
- package/cjs/inputs/Label/index.js +45 -24
- package/cjs/inputs/Label/index.js.map +7 -0
- package/cjs/inputs/OtpInput/index.js +142 -112
- package/cjs/inputs/OtpInput/index.js.map +7 -0
- package/cjs/inputs/Radio/index.js +131 -61
- package/cjs/inputs/Radio/index.js.map +7 -0
- package/cjs/inputs/Select/index.js +59 -36
- package/cjs/inputs/Select/index.js.map +7 -0
- package/cjs/inputs/index.js +62 -69
- package/cjs/inputs/index.js.map +7 -0
- package/cjs/inputs/inputsScenarios/index.js +533 -0
- package/cjs/inputs/inputsScenarios.js.map +7 -0
- package/cjs/internal/index.js +36 -346
- package/cjs/internal.js.map +7 -0
- package/cjs/lazy/index.js +109 -516
- package/cjs/lazy.js.map +7 -0
- package/cjs/locales/el/index.js +35 -0
- package/cjs/locales/el.js.map +7 -0
- package/cjs/registry/index.js +190 -142
- package/cjs/registry.js.map +7 -0
- package/cjs/types/index.js +22 -5
- package/cjs/types.js.map +7 -0
- package/cjs/utils/index.js +79 -83
- package/cjs/utils.js.map +7 -0
- package/cjs/validators/index.js +131 -164
- package/cjs/validators/index.js.map +7 -0
- package/cjs/validators/types/index.js +16 -5
- package/cjs/validators/types.js.map +7 -0
- package/cjs/validators/utils/afm/index.js +38 -21
- package/cjs/validators/utils/afm.js.map +7 -0
- package/cjs/validators/utils/date/index.js +138 -0
- package/cjs/validators/utils/date.js.map +7 -0
- package/cjs/validators/utils/datetime/index.js +151 -0
- package/cjs/validators/utils/datetime.js.map +7 -0
- package/cjs/validators/utils/file/index.js +44 -47
- package/cjs/validators/utils/file.js.map +7 -0
- package/cjs/validators/utils/iban/index.js +36 -17
- package/cjs/validators/utils/iban.js.map +7 -0
- package/cjs/validators/utils/image/index.js +88 -112
- package/cjs/validators/utils/image.js.map +7 -0
- package/cjs/validators/utils/index.js +99 -159
- package/cjs/validators/utils/index.js.map +7 -0
- package/cjs/validators/utils/int/index.js +35 -13
- package/cjs/validators/utils/int.js.map +7 -0
- package/cjs/validators/utils/number/index.js +34 -12
- package/cjs/validators/utils/number.js.map +7 -0
- package/cjs/validators/utils/otp/index.js +35 -13
- package/cjs/validators/utils/otp.js.map +7 -0
- package/cjs/validators/utils/phone/index.js +113 -58
- package/cjs/validators/utils/phone.js.map +7 -0
- package/cjs/validators/utils/postal_code/index.js +36 -16
- package/cjs/validators/utils/postal_code.js.map +7 -0
- package/cjs/validators/utils/text_limit/index.js +40 -25
- package/cjs/validators/utils/text_limit.js.map +7 -0
- package/cjs/validators/utils/uuid4/index.js +34 -13
- package/cjs/validators/utils/uuid4.js.map +7 -0
- package/index.d.ts +4 -1
- package/index.js +13 -4
- package/index.js.map +7 -0
- package/inputs/AutoCompleteInput/AutoComplete.stories.d.ts +2 -1
- package/inputs/AutoCompleteInput/__stories__/Default.d.ts +3 -2
- package/inputs/AutoCompleteInput/__stories__/Multiple.d.ts +3 -0
- package/inputs/AutoCompleteInput/index.d.ts +2 -2
- package/inputs/AutoCompleteInput/index.js +62 -37
- package/inputs/AutoCompleteInput/index.js.map +7 -0
- package/inputs/AutoCompleteInput/index.test.d.ts +1 -0
- package/inputs/Checkboxes/Checkboxes.stories.d.ts +3 -3
- package/inputs/Checkboxes/__stories__/Conditional.d.ts +3 -2
- package/inputs/Checkboxes/__stories__/Default.d.ts +2 -2
- package/inputs/Checkboxes/__stories__/WithDivider.d.ts +2 -2
- package/inputs/Checkboxes/index.d.ts +2 -1
- package/inputs/Checkboxes/index.js +73 -87
- package/inputs/Checkboxes/index.js.map +7 -0
- package/inputs/Checkboxes/index.test.d.ts +1 -0
- package/inputs/DateInput/DateInput.stories.d.ts +1 -1
- package/inputs/DateInput/__stories__/Default.d.ts +2 -2
- package/inputs/DateInput/index.d.ts +3 -4
- package/inputs/DateInput/index.js +91 -99
- package/inputs/DateInput/index.js.map +7 -0
- package/inputs/DateInput/index.test.d.ts +1 -0
- package/inputs/DateTimeInput/DateTimeInput.stories.d.ts +7 -0
- package/inputs/DateTimeInput/__stories__/Default.d.ts +3 -0
- package/inputs/DateTimeInput/index.d.ts +13 -0
- package/inputs/DateTimeInput/index.js +176 -0
- package/inputs/DateTimeInput/index.js.map +7 -0
- package/inputs/DateTimeInput/index.test.d.ts +1 -0
- package/inputs/DateTimeInput/package.json +6 -0
- package/inputs/FileInput/FileInput.stories.d.ts +1 -1
- package/inputs/FileInput/__stories__/Default.d.ts +2 -2
- package/inputs/FileInput/index.js +43 -54
- package/inputs/FileInput/index.js.map +7 -0
- package/inputs/FileInput/index.test.d.ts +1 -0
- package/inputs/ImageInput/ImageInput.stories.d.ts +3 -3
- package/inputs/ImageInput/__stories__/Default.d.ts +2 -2
- package/inputs/ImageInput/__stories__/MaxSize.d.ts +3 -0
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension.d.ts +2 -2
- package/inputs/ImageInput/__stories__/WithInvalidImageSize.d.ts +2 -2
- package/inputs/ImageInput/index.js +63 -75
- package/inputs/ImageInput/index.js.map +7 -0
- package/inputs/ImageInput/index.test.d.ts +1 -0
- package/inputs/Input/Input.stories.d.ts +11 -10
- package/inputs/Input/__stories__/AFM.d.ts +2 -2
- package/inputs/Input/__stories__/Boolean.d.ts +2 -2
- package/inputs/Input/__stories__/IBAN.d.ts +2 -2
- package/inputs/Input/__stories__/Integer.d.ts +2 -2
- package/inputs/Input/__stories__/LandlineNumber.d.ts +2 -2
- package/inputs/Input/__stories__/MobilePhone.d.ts +2 -2
- package/inputs/Input/__stories__/PhoneNumber.d.ts +2 -2
- package/inputs/Input/__stories__/PostalCode.d.ts +2 -2
- package/inputs/Input/__stories__/String.d.ts +3 -0
- package/inputs/Input/__stories__/StringWithTrimValidation.d.ts +3 -0
- package/inputs/Input/__stories__/TextWithLimit.d.ts +3 -0
- package/inputs/Input/index.js +74 -66
- package/inputs/Input/index.js.map +7 -0
- package/inputs/Input/index.test.d.ts +1 -0
- package/inputs/Input/inputsInputScenarios/index.js +406 -0
- package/{FieldArray/__stories__/Default → inputs/Input/inputsInputScenarios}/package.json +1 -1
- package/inputs/Input/inputsInputScenarios.d.ts +57 -0
- package/inputs/Input/inputsInputScenarios.js.map +7 -0
- package/inputs/Label/Label.stories.d.ts +1 -1
- package/inputs/Label/__stories__/Default.d.ts +2 -2
- package/inputs/Label/index.d.ts +1 -3
- package/inputs/Label/index.js +12 -17
- package/inputs/Label/index.js.map +7 -0
- package/inputs/Label/index.test.d.ts +1 -0
- package/inputs/OtpInput/OtpInput.stories.d.ts +1 -1
- package/inputs/OtpInput/__stories__/Default.d.ts +2 -2
- package/inputs/OtpInput/index.d.ts +9 -2
- package/inputs/OtpInput/index.js +109 -103
- package/inputs/OtpInput/index.js.map +7 -0
- package/inputs/OtpInput/index.test.d.ts +1 -0
- package/inputs/Radio/Radio.stories.d.ts +3 -3
- package/inputs/Radio/__stories__/Conditional.d.ts +3 -2
- package/inputs/Radio/__stories__/Default.d.ts +2 -2
- package/inputs/Radio/__stories__/WithDivider.d.ts +2 -2
- package/inputs/Radio/index.d.ts +6 -1
- package/inputs/Radio/index.js +102 -55
- package/inputs/Radio/index.js.map +7 -0
- package/inputs/Radio/index.test.d.ts +1 -0
- package/inputs/Select/Select.stories.d.ts +1 -1
- package/inputs/Select/__stories__/Default.d.ts +2 -2
- package/inputs/Select/index.d.ts +1 -1
- package/inputs/Select/index.js +31 -31
- package/inputs/Select/index.js.map +7 -0
- package/inputs/Select/index.test.d.ts +1 -0
- package/inputs/index.js +21 -9
- package/inputs/index.js.map +7 -0
- package/inputs/inputsScenarios/index.js +499 -0
- package/inputs/inputsScenarios/package.json +6 -0
- package/inputs/inputsScenarios.d.ts +296 -0
- package/inputs/inputsScenarios.js.map +7 -0
- package/internal/index.js +10 -34
- package/internal.d.ts +2 -31
- package/internal.js.map +7 -0
- package/lazy/index.js +75 -393
- package/locales/el/index.js +6 -0
- package/{Form.stories → locales/el}/package.json +1 -1
- package/locales/el.d.ts +2 -0
- package/locales/el.js.map +7 -0
- package/package.json +7 -8
- package/registry/index.js +125 -98
- package/src/Field/ErrorGroup.tsx +84 -0
- package/src/Field/FieldBase.tsx +36 -22
- package/src/Field/FieldBaseContainer.tsx +7 -4
- package/src/Field/FieldConditional.tsx +5 -1
- package/src/Field/index.tsx +27 -3
- package/src/Field/types.tsx +73 -5
- package/src/Field/utils/calculateField.ts +49 -0
- package/src/Field/utils/evaluateFieldWithConditions.ts +30 -0
- package/src/Field/utils/index.ts +82 -0
- package/src/Field/utils/useField.ts +58 -0
- package/src/FieldArray/FieldArray.stories.js +2 -2
- package/src/FieldArray/FormDialog.tsx +379 -0
- package/src/FieldArray/__stories__/Default.tsx +1 -0
- package/src/FieldArray/__stories__/WithExactLength.tsx +77 -13
- package/src/FieldArray/index.test.tsx +24 -0
- package/src/FieldArray/index.tsx +92 -39
- package/src/FieldObject/index.tsx +28 -8
- package/src/Fieldset/index.tsx +5 -5
- package/src/Fieldset/types.tsx +5 -3
- package/src/FormBuilder/FormBuilder.stories.js +3 -1
- package/src/FormBuilder/__stories__/AutoErrorGrouping.tsx +63 -0
- package/src/FormBuilder/__stories__/ErrorGrouping.tsx +43 -0
- package/{FormBuilder/FormBuilder.mdx → src/FormBuilder/doc.mdx} +20 -33
- package/src/FormBuilder/index.test.tsx +29 -0
- package/src/FormBuilder/index.tsx +263 -1
- package/src/FormBuilder/interaction.test.tsx +32 -0
- package/src/FormBuilder/scenarios.test.tsx +1971 -0
- package/src/FormContext.tsx +1 -2
- package/src/MultiplicityField/MultiplicityField.stories.js +6 -6
- package/src/MultiplicityField/__stories__/PreviewDisplay.tsx +2 -2
- 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 +31 -15
- package/{MultiplicityField/MultiplicityField.mdx → src/MultiplicityField/doc.mdx} +12 -16
- package/src/MultiplicityField/index.test.tsx +40 -0
- package/src/MultiplicityField/index.tsx +22 -35
- package/src/MultiplicityField/types.ts +21 -0
- package/src/Questions/Questions.stories.js +1 -1
- package/src/Questions/Questions.tsx +4 -4
- package/src/Questions/Step/StepArrayReview.tsx +1 -1
- package/src/Questions/Step/StepTitle.tsx +5 -3
- package/src/Questions/Step/index.ts +0 -1
- package/src/Questions/Step/types.tsx +1 -0
- package/src/Questions/__snapshots__/index.spec.tsx.snap +73 -587
- package/src/Questions/{index.mdx → doc.mdx} +13 -16
- package/src/Questions/index.spec.tsx +17 -5
- package/src/Questions/index.test.tsx +20 -0
- package/src/Questions/types.tsx +1 -0
- package/src/create-simple-form.mdx +2 -6
- package/{index.mdx → src/doc.mdx} +4 -8
- package/src/index.ts +4 -1
- package/src/inputs/AutoCompleteInput/AutoComplete.stories.js +2 -1
- package/src/inputs/AutoCompleteInput/__stories__/Default.tsx +19 -18
- package/src/inputs/AutoCompleteInput/__stories__/Multiple.tsx +47 -0
- package/src/inputs/AutoCompleteInput/doc.mdx +18 -0
- package/src/inputs/AutoCompleteInput/index.test.tsx +24 -0
- package/src/inputs/AutoCompleteInput/index.tsx +46 -29
- package/src/inputs/Checkboxes/Checkboxes.stories.js +3 -3
- package/src/inputs/Checkboxes/__stories__/Conditional.tsx +2 -3
- package/src/inputs/Checkboxes/doc.mdx +23 -0
- package/src/inputs/Checkboxes/index.test.tsx +28 -0
- package/src/inputs/Checkboxes/index.tsx +39 -33
- package/src/inputs/DateInput/DateInput.stories.js +1 -1
- package/src/inputs/DateInput/__stories__/Default.tsx +16 -15
- package/src/inputs/DateInput/doc.mdx +16 -0
- package/src/inputs/DateInput/index.test.tsx +20 -0
- package/src/inputs/DateInput/index.tsx +11 -9
- package/src/inputs/DateTimeInput/DateTimeInput.stories.js +8 -0
- package/src/inputs/DateTimeInput/__stories__/Default.tsx +25 -0
- package/src/inputs/DateTimeInput/doc.mdx +16 -0
- package/src/inputs/DateTimeInput/index.test.tsx +18 -0
- package/src/inputs/DateTimeInput/index.tsx +189 -0
- package/src/inputs/FileInput/FileInput.stories.js +1 -1
- package/src/inputs/FileInput/doc.mdx +15 -0
- package/src/inputs/FileInput/index.test.tsx +20 -0
- package/src/inputs/FileInput/index.tsx +8 -9
- package/src/inputs/ImageInput/ImageInput.stories.js +3 -3
- package/src/inputs/ImageInput/__stories__/MaxSize.tsx +37 -0
- package/src/inputs/ImageInput/__stories__/WithInvalidImageDimension.tsx +2 -0
- package/src/inputs/ImageInput/doc.mdx +23 -0
- package/src/inputs/ImageInput/index.test.tsx +32 -0
- package/src/inputs/ImageInput/index.tsx +16 -16
- package/src/inputs/Input/Input.stories.js +11 -10
- package/src/inputs/Input/__stories__/LandlineNumber.tsx +2 -1
- package/src/inputs/Input/__stories__/MobilePhone.tsx +1 -0
- package/src/inputs/Input/__stories__/PhoneNumber.tsx +1 -0
- package/src/inputs/Input/__stories__/PostalCode.tsx +1 -0
- package/src/inputs/Input/__stories__/{Default.tsx → String.tsx} +2 -2
- package/src/inputs/Input/__stories__/StringWithTrimValidation.tsx +26 -0
- package/src/inputs/Input/__stories__/{TextWithCharacterLimit.tsx → TextWithLimit.tsx} +3 -2
- package/src/inputs/Input/doc.mdx +56 -0
- package/src/inputs/Input/index.test.tsx +60 -0
- package/src/inputs/Input/index.tsx +40 -30
- package/src/inputs/Input/inputsInputScenarios.ts +404 -0
- package/src/inputs/Label/Label.stories.js +1 -1
- package/src/inputs/Label/__stories__/Default.tsx +3 -1
- package/src/inputs/Label/doc.mdx +14 -0
- package/src/inputs/Label/index.test.tsx +20 -0
- package/src/inputs/Label/index.tsx +3 -10
- package/src/inputs/OtpInput/OtpInput.stories.js +1 -1
- package/src/inputs/OtpInput/doc.mdx +16 -0
- package/src/inputs/OtpInput/index.test.tsx +20 -0
- package/src/inputs/OtpInput/index.tsx +4 -3
- package/src/inputs/Radio/Radio.stories.js +3 -3
- package/src/inputs/Radio/__stories__/Conditional.tsx +4 -1
- package/src/inputs/Radio/doc.mdx +23 -0
- package/src/inputs/Radio/index.test.tsx +28 -0
- package/src/inputs/Radio/index.tsx +79 -9
- package/src/inputs/Select/Select.stories.js +1 -1
- package/src/inputs/Select/doc.mdx +13 -0
- package/src/inputs/Select/index.test.tsx +20 -0
- package/src/inputs/Select/index.tsx +11 -4
- package/src/inputs/inputsScenarios.ts +496 -0
- package/src/installation.mdx +2 -5
- package/src/internal.ts +2 -31
- package/src/lazy.js +76 -59
- package/src/locales/el.ts +3 -0
- package/src/registry.js +108 -88
- package/src/types.tsx +11 -64
- package/src/utils.ts +34 -33
- package/src/validators/index.ts +90 -84
- package/src/validators/utils/date.ts +107 -0
- package/src/validators/utils/datetime.ts +130 -0
- package/src/validators/utils/file.ts +11 -9
- package/src/validators/utils/index.ts +2 -0
- package/src/validators/utils/int.ts +1 -1
- package/src/validators/utils/number.ts +1 -1
- package/src/validators/utils/phone.ts +63 -72
- package/src/validators/utils/postal_code.ts +1 -1
- package/src/validators/utils/uuid4.ts +2 -1
- package/src/validators/validators.spec.ts +6 -40
- package/types/index.js +2 -1
- package/types.d.ts +6 -35
- package/types.js.map +7 -0
- package/utils/index.js +57 -77
- package/utils.js.map +7 -0
- package/validators/index.js +112 -150
- package/validators/index.js.map +7 -0
- package/validators/types/index.js +1 -1
- package/validators/types.js.map +7 -0
- package/validators/utils/afm/index.js +16 -16
- package/validators/utils/afm.js.map +7 -0
- package/validators/utils/date/index.js +103 -0
- package/validators/utils/date/package.json +6 -0
- package/validators/utils/date.d.ts +9 -0
- package/validators/utils/date.js.map +7 -0
- package/validators/utils/datetime/index.js +116 -0
- package/{Questions/Questions.stories → validators/utils/datetime}/package.json +1 -1
- package/validators/utils/datetime.d.ts +9 -0
- package/validators/utils/datetime.js.map +7 -0
- package/validators/utils/file/index.js +22 -42
- package/validators/utils/file.js.map +7 -0
- package/validators/utils/iban/index.js +14 -12
- package/validators/utils/iban.js.map +7 -0
- package/validators/utils/image/index.js +66 -106
- package/validators/utils/image.js.map +7 -0
- package/validators/utils/index.d.ts +2 -0
- package/validators/utils/index.js +56 -48
- package/validators/utils/index.js.map +7 -0
- package/validators/utils/int/index.js +13 -8
- package/validators/utils/int.js.map +7 -0
- package/validators/utils/number/index.js +12 -7
- package/validators/utils/number.js.map +7 -0
- package/validators/utils/otp/index.js +13 -8
- package/validators/utils/otp.js.map +7 -0
- package/validators/utils/phone/index.js +89 -51
- package/validators/utils/phone.d.ts +1 -1
- package/validators/utils/phone.js.map +7 -0
- package/validators/utils/postal_code/index.js +14 -11
- package/validators/utils/postal_code.d.ts +1 -1
- package/validators/utils/postal_code.js.map +7 -0
- package/validators/utils/text_limit/index.js +18 -20
- package/validators/utils/text_limit.js.map +7 -0
- package/validators/utils/uuid4/index.js +12 -8
- package/validators/utils/uuid4.js.map +7 -0
- package/Field/utils.d.ts +0 -5
- package/FieldArray/FieldArray.stories/index.js +0 -8
- package/FieldArray/FieldArray.stories.playwright.json +0 -353
- package/FieldArray/__stories__/Default/index.js +0 -88
- package/FieldArray/__stories__/WithExactLength/index.js +0 -88
- package/FieldArray/__stories__/WithExactLength/package.json +0 -6
- package/Form.stories/index.js +0 -3
- package/FormBuilder/FormBuilder/index.js +0 -152
- package/FormBuilder/FormBuilder.d.ts +0 -5
- package/FormBuilder/FormBuilder.stories/index.js +0 -7
- package/FormBuilder/FormBuilder.stories/package.json +0 -6
- package/FormBuilder/FormBuilder.stories.playwright.json +0 -52
- package/FormBuilder/__stories__/Default/index.js +0 -26
- package/FormBuilder/__stories__/Default/package.json +0 -6
- package/MultiplicityField/MultiplicityField.stories/index.js +0 -12
- package/MultiplicityField/MultiplicityField.stories/package.json +0 -6
- package/MultiplicityField/MultiplicityField.stories.playwright.json +0 -1370
- package/MultiplicityField/__stories__/Default/index.js +0 -95
- package/MultiplicityField/__stories__/Default/package.json +0 -6
- package/MultiplicityField/__stories__/PreviewDisplay/index.js +0 -72
- package/MultiplicityField/__stories__/PreviewDisplay/package.json +0 -6
- package/MultiplicityField/__stories__/WithExactLength/index.js +0 -90
- package/MultiplicityField/__stories__/WithExactLength/package.json +0 -6
- package/MultiplicityField/__stories__/WithMaxLength/index.js +0 -93
- package/MultiplicityField/__stories__/WithMaxLength/package.json +0 -6
- package/MultiplicityField/__stories__/WithMinAndMaxLength/index.js +0 -94
- package/MultiplicityField/__stories__/WithMinAndMaxLength/package.json +0 -6
- package/MultiplicityField/__stories__/WithMinLength/index.js +0 -93
- package/MultiplicityField/__stories__/WithMinLength/package.json +0 -6
- package/Questions/Questions.stories/index.js +0 -7
- package/Questions/__snapshots__/index.spec.tsx.snap +0 -596
- package/Questions/__stories__/Default/index.js +0 -102
- package/Questions/__stories__/Default/package.json +0 -6
- package/Questions/index.mdx +0 -415
- package/Questions/index.spec/index.js +0 -59
- package/cjs/Field/index.mdx +0 -6
- package/cjs/FieldArray/FieldArray.stories/index.js +0 -38
- package/cjs/FieldArray/FieldArray.stories.playwright.json +0 -353
- package/cjs/FieldArray/__stories__/Default/index.js +0 -98
- package/cjs/FieldArray/__stories__/WithExactLength/index.js +0 -98
- package/cjs/Form.stories/index.js +0 -9
- package/cjs/FormBuilder/FormBuilder/index.js +0 -162
- package/cjs/FormBuilder/FormBuilder.mdx +0 -256
- package/cjs/FormBuilder/FormBuilder.stories/index.js +0 -26
- package/cjs/FormBuilder/FormBuilder.stories.playwright.json +0 -52
- package/cjs/FormBuilder/__stories__/Default/index.js +0 -36
- package/cjs/MultiplicityField/MultiplicityField.mdx +0 -590
- package/cjs/MultiplicityField/MultiplicityField.stories/index.js +0 -86
- package/cjs/MultiplicityField/MultiplicityField.stories.playwright.json +0 -1370
- package/cjs/MultiplicityField/__stories__/Default/index.js +0 -105
- package/cjs/MultiplicityField/__stories__/PreviewDisplay/index.js +0 -82
- package/cjs/MultiplicityField/__stories__/WithExactLength/index.js +0 -100
- package/cjs/MultiplicityField/__stories__/WithMaxLength/index.js +0 -103
- package/cjs/MultiplicityField/__stories__/WithMinAndMaxLength/index.js +0 -104
- package/cjs/MultiplicityField/__stories__/WithMinLength/index.js +0 -103
- package/cjs/Questions/Questions.stories/index.js +0 -26
- package/cjs/Questions/__snapshots__/index.spec.tsx.snap +0 -596
- package/cjs/Questions/__stories__/Default/index.js +0 -113
- package/cjs/Questions/index.mdx +0 -415
- package/cjs/Questions/index.spec/index.js +0 -63
- package/cjs/create-simple-form.mdx +0 -539
- package/cjs/index.mdx +0 -51
- package/cjs/inputs/AutoCompleteInput/AutoComplete.stories/index.js +0 -26
- package/cjs/inputs/AutoCompleteInput/__stories__/Default/index.js +0 -56
- package/cjs/inputs/Checkboxes/Checkboxes.stories/index.js +0 -50
- package/cjs/inputs/Checkboxes/Checkboxes.stories.playwright.json +0 -85
- package/cjs/inputs/Checkboxes/__stories__/Conditional/index.js +0 -102
- package/cjs/inputs/Checkboxes/__stories__/Default/index.js +0 -50
- package/cjs/inputs/Checkboxes/__stories__/WithDivider/index.js +0 -51
- package/cjs/inputs/Checkboxes/index.mdx +0 -0
- package/cjs/inputs/DateInput/DateInput.stories/index.js +0 -26
- package/cjs/inputs/DateInput/DateInput.stories.playwright.json +0 -72
- package/cjs/inputs/DateInput/__stories__/Default/index.js +0 -33
- package/cjs/inputs/FileInput/FileInput.stories/index.js +0 -26
- package/cjs/inputs/FileInput/FileInput.stories.playwright.json +0 -75
- package/cjs/inputs/FileInput/__stories__/Default/index.js +0 -30
- package/cjs/inputs/ImageInput/ImageInput.stories/index.js +0 -50
- package/cjs/inputs/ImageInput/ImageInput.stories.playwright.json +0 -77
- package/cjs/inputs/ImageInput/__stories__/Default/index.js +0 -38
- package/cjs/inputs/ImageInput/__stories__/WithInvalidImageDimension/index.js +0 -46
- package/cjs/inputs/ImageInput/__stories__/WithInvalidImageSize/index.js +0 -43
- package/cjs/inputs/Input/Input.stories/index.js +0 -134
- package/cjs/inputs/Input/Input.stories.playwright.json +0 -376
- package/cjs/inputs/Input/__stories__/AFM/index.js +0 -32
- package/cjs/inputs/Input/__stories__/Boolean/index.js +0 -33
- package/cjs/inputs/Input/__stories__/Default/index.js +0 -33
- package/cjs/inputs/Input/__stories__/IBAN/index.js +0 -33
- package/cjs/inputs/Input/__stories__/Integer/index.js +0 -41
- package/cjs/inputs/Input/__stories__/LandlineNumber/index.js +0 -36
- package/cjs/inputs/Input/__stories__/MobilePhone/index.js +0 -36
- package/cjs/inputs/Input/__stories__/PhoneNumber/index.js +0 -35
- package/cjs/inputs/Input/__stories__/PostalCode/index.js +0 -35
- package/cjs/inputs/Input/__stories__/TextWithCharacterLimit/index.js +0 -39
- package/cjs/inputs/Input/index.mdx +0 -8
- package/cjs/inputs/Label/Label.stories/index.js +0 -26
- package/cjs/inputs/Label/Label.stories.playwright.json +0 -40
- package/cjs/inputs/Label/__stories__/Default/index.js +0 -37
- package/cjs/inputs/Label/index.mdx +0 -0
- package/cjs/inputs/OtpInput/OtpInput.stories/index.js +0 -26
- package/cjs/inputs/OtpInput/__stories__/Default/index.js +0 -39
- package/cjs/inputs/Radio/Radio.stories/index.js +0 -50
- package/cjs/inputs/Radio/Radio.stories.playwright.json +0 -73
- package/cjs/inputs/Radio/__stories__/Conditional/index.js +0 -102
- package/cjs/inputs/Radio/__stories__/Default/index.js +0 -55
- package/cjs/inputs/Radio/__stories__/WithDivider/index.js +0 -56
- package/cjs/inputs/Radio/index.mdx +0 -0
- package/cjs/inputs/Select/Select.stories/index.js +0 -26
- package/cjs/inputs/Select/Select.stories.playwright.json +0 -22
- package/cjs/inputs/Select/__stories__/Default/index.js +0 -61
- package/cjs/installation.mdx +0 -68
- package/cjs/validators/validators.spec/index.js +0 -87
- package/create-simple-form.mdx +0 -539
- package/inputs/AutoCompleteInput/AutoComplete.stories/index.js +0 -7
- package/inputs/AutoCompleteInput/AutoComplete.stories/package.json +0 -6
- package/inputs/AutoCompleteInput/__stories__/Default/index.js +0 -46
- package/inputs/AutoCompleteInput/__stories__/Default/package.json +0 -6
- package/inputs/Checkboxes/Checkboxes.stories/index.js +0 -9
- package/inputs/Checkboxes/Checkboxes.stories/package.json +0 -6
- package/inputs/Checkboxes/Checkboxes.stories.playwright.json +0 -85
- package/inputs/Checkboxes/__stories__/Conditional/index.js +0 -92
- package/inputs/Checkboxes/__stories__/Conditional/package.json +0 -6
- package/inputs/Checkboxes/__stories__/Default/index.js +0 -40
- package/inputs/Checkboxes/__stories__/Default/package.json +0 -6
- package/inputs/Checkboxes/__stories__/WithDivider/index.js +0 -41
- package/inputs/Checkboxes/__stories__/WithDivider/package.json +0 -6
- package/inputs/Checkboxes/index.mdx +0 -0
- package/inputs/DateInput/DateInput.stories/index.js +0 -7
- package/inputs/DateInput/DateInput.stories/package.json +0 -6
- package/inputs/DateInput/DateInput.stories.playwright.json +0 -72
- package/inputs/DateInput/__stories__/Default/index.js +0 -23
- package/inputs/FileInput/FileInput.stories/index.js +0 -7
- package/inputs/FileInput/FileInput.stories/package.json +0 -6
- package/inputs/FileInput/FileInput.stories.playwright.json +0 -75
- package/inputs/FileInput/__stories__/Default/index.js +0 -20
- package/inputs/FileInput/__stories__/Default/package.json +0 -6
- package/inputs/ImageInput/ImageInput.stories/index.js +0 -9
- package/inputs/ImageInput/ImageInput.stories/package.json +0 -6
- package/inputs/ImageInput/ImageInput.stories.playwright.json +0 -77
- package/inputs/ImageInput/__stories__/Default/index.js +0 -28
- package/inputs/ImageInput/__stories__/Default/package.json +0 -6
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension/index.js +0 -36
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension/package.json +0 -6
- package/inputs/ImageInput/__stories__/WithInvalidImageSize/index.js +0 -33
- package/inputs/ImageInput/__stories__/WithInvalidImageSize/package.json +0 -6
- package/inputs/Input/Input.stories/index.js +0 -16
- package/inputs/Input/Input.stories/package.json +0 -6
- package/inputs/Input/Input.stories.playwright.json +0 -376
- package/inputs/Input/__stories__/AFM/index.js +0 -22
- package/inputs/Input/__stories__/AFM/package.json +0 -6
- package/inputs/Input/__stories__/Boolean/index.js +0 -23
- package/inputs/Input/__stories__/Boolean/package.json +0 -6
- package/inputs/Input/__stories__/Default/index.js +0 -23
- package/inputs/Input/__stories__/Default/package.json +0 -6
- package/inputs/Input/__stories__/Default.d.ts +0 -3
- package/inputs/Input/__stories__/IBAN/index.js +0 -23
- package/inputs/Input/__stories__/IBAN/package.json +0 -6
- package/inputs/Input/__stories__/Integer/index.js +0 -31
- package/inputs/Input/__stories__/Integer/package.json +0 -6
- package/inputs/Input/__stories__/LandlineNumber/index.js +0 -26
- package/inputs/Input/__stories__/LandlineNumber/package.json +0 -6
- package/inputs/Input/__stories__/MobilePhone/index.js +0 -26
- package/inputs/Input/__stories__/MobilePhone/package.json +0 -6
- package/inputs/Input/__stories__/PhoneNumber/index.js +0 -25
- package/inputs/Input/__stories__/PhoneNumber/package.json +0 -6
- package/inputs/Input/__stories__/PostalCode/index.js +0 -25
- package/inputs/Input/__stories__/PostalCode/package.json +0 -6
- package/inputs/Input/__stories__/TextWithCharacterLimit/index.js +0 -29
- package/inputs/Input/__stories__/TextWithCharacterLimit/package.json +0 -6
- package/inputs/Input/__stories__/TextWithCharacterLimit.d.ts +0 -3
- package/inputs/Input/index.mdx +0 -8
- package/inputs/Label/Label.stories/index.js +0 -7
- package/inputs/Label/Label.stories/package.json +0 -6
- package/inputs/Label/Label.stories.playwright.json +0 -40
- package/inputs/Label/__stories__/Default/index.js +0 -27
- package/inputs/Label/__stories__/Default/package.json +0 -6
- package/inputs/Label/index.mdx +0 -0
- package/inputs/OtpInput/OtpInput.stories/index.js +0 -7
- package/inputs/OtpInput/OtpInput.stories/package.json +0 -6
- package/inputs/OtpInput/__stories__/Default/index.js +0 -29
- package/inputs/OtpInput/__stories__/Default/package.json +0 -6
- package/inputs/Radio/Radio.stories/index.js +0 -9
- package/inputs/Radio/Radio.stories/package.json +0 -6
- package/inputs/Radio/Radio.stories.playwright.json +0 -73
- package/inputs/Radio/__stories__/Conditional/index.js +0 -92
- package/inputs/Radio/__stories__/Conditional/package.json +0 -6
- package/inputs/Radio/__stories__/Default/index.js +0 -45
- package/inputs/Radio/__stories__/Default/package.json +0 -6
- package/inputs/Radio/__stories__/WithDivider/index.js +0 -46
- package/inputs/Radio/__stories__/WithDivider/package.json +0 -6
- package/inputs/Radio/index.mdx +0 -0
- package/inputs/Select/Select.stories/index.js +0 -7
- package/inputs/Select/Select.stories/package.json +0 -6
- package/inputs/Select/Select.stories.playwright.json +0 -22
- package/inputs/Select/__stories__/Default/index.js +0 -51
- package/inputs/Select/__stories__/Default/package.json +0 -6
- package/installation.mdx +0 -68
- package/lazy.d.ts +0 -69
- package/registry.d.ts +0 -64
- package/src/Field/index.mdx +0 -6
- package/src/Field/utils.ts +0 -191
- package/src/FieldArray/FieldArray.stories.playwright.json +0 -353
- package/src/FormBuilder/FormBuilder.mdx +0 -256
- package/src/FormBuilder/FormBuilder.stories.playwright.json +0 -52
- package/src/FormBuilder/FormBuilder.tsx +0 -166
- package/src/MultiplicityField/MultiplicityField.mdx +0 -590
- package/src/MultiplicityField/MultiplicityField.stories.playwright.json +0 -1370
- package/src/index.mdx +0 -51
- package/src/inputs/Checkboxes/Checkboxes.stories.playwright.json +0 -85
- package/src/inputs/Checkboxes/index.mdx +0 -0
- package/src/inputs/DateInput/DateInput.stories.playwright.json +0 -72
- package/src/inputs/FileInput/FileInput.stories.playwright.json +0 -75
- package/src/inputs/ImageInput/ImageInput.stories.playwright.json +0 -77
- package/src/inputs/Input/Input.stories.playwright.json +0 -376
- package/src/inputs/Input/index.mdx +0 -8
- package/src/inputs/Label/Label.stories.playwright.json +0 -40
- package/src/inputs/Label/index.mdx +0 -0
- package/src/inputs/Radio/Radio.stories.playwright.json +0 -73
- package/src/inputs/Radio/index.mdx +0 -0
- package/src/inputs/Select/Select.stories.playwright.json +0 -22
- package/validators/validators.spec/index.js +0 -85
- /package/{Field/index.mdx → src/Field/doc.mdx} +0 -0
package/src/utils.ts
CHANGED
|
@@ -38,41 +38,42 @@ const parseErrorSchema = (
|
|
|
38
38
|
);
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
export const yupResolver =
|
|
42
|
-
schema: any,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
41
|
+
export const yupResolver =
|
|
42
|
+
(schema: any, schemaOptions: any = {}, resolverOptions: any = {}) =>
|
|
43
|
+
async (values, context, options) => {
|
|
44
|
+
try {
|
|
45
|
+
if (schemaOptions.context && process.env.NODE_ENV === 'development') {
|
|
46
|
+
console.warn(
|
|
47
|
+
"You should not used the yup options context. Please, use the 'useForm' context object instead"
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const result = await schema[
|
|
52
|
+
resolverOptions.mode === 'sync' ? 'validateSync' : 'validate'
|
|
53
|
+
](
|
|
54
|
+
values,
|
|
55
|
+
Object.assign({ abortEarly: false }, schemaOptions, { context })
|
|
51
56
|
);
|
|
52
|
-
}
|
|
53
57
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
](values, Object.assign({ abortEarly: false }, schemaOptions, { context }));
|
|
58
|
+
if (options.shouldUseNativeValidation)
|
|
59
|
+
validateFieldsNatively({}, options);
|
|
57
60
|
|
|
58
|
-
|
|
61
|
+
return {
|
|
62
|
+
values: resolverOptions.rawValues ? values : result,
|
|
63
|
+
errors: {},
|
|
64
|
+
};
|
|
65
|
+
} catch (e) {
|
|
66
|
+
if (!e.inner) {
|
|
67
|
+
throw e;
|
|
68
|
+
}
|
|
59
69
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
70
|
+
const parsed = parseErrorSchema(
|
|
71
|
+
e,
|
|
72
|
+
!options.shouldUseNativeValidation && options.criteriaMode === 'all'
|
|
73
|
+
);
|
|
74
|
+
return {
|
|
75
|
+
values: {},
|
|
76
|
+
errors: parsed,
|
|
77
|
+
};
|
|
67
78
|
}
|
|
68
|
-
|
|
69
|
-
const parsed = parseErrorSchema(
|
|
70
|
-
e,
|
|
71
|
-
!options.shouldUseNativeValidation && options.criteriaMode === 'all'
|
|
72
|
-
);
|
|
73
|
-
return {
|
|
74
|
-
values: {},
|
|
75
|
-
errors: parsed,
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
+
};
|
package/src/validators/index.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { MutableRefObject, useMemo } from 'react';
|
|
2
|
-
import dayjs from 'dayjs';
|
|
3
|
-
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
4
2
|
import * as yup from 'yup';
|
|
5
3
|
import { AnyObjectSchema, StringSchema } from 'yup';
|
|
6
4
|
import { RequiredArraySchema } from 'yup/lib/array';
|
|
@@ -22,16 +20,15 @@ import {
|
|
|
22
20
|
POSTALCODE_VALIDATOR,
|
|
23
21
|
UUID4_VALIDATOR,
|
|
24
22
|
IMAGE_DIMENSION_VALIDATOR,
|
|
23
|
+
DATE_VALIDATOR,
|
|
24
|
+
LATER_THAN_VALIDATOR,
|
|
25
|
+
EARLIER_THAN_VALIDATOR,
|
|
26
|
+
DATETIME_VALIDATOR,
|
|
27
|
+
LATER_THAN_DATETIME_VALIDATOR,
|
|
28
|
+
EARLIER_THAN_DATETIME_VALIDATOR,
|
|
25
29
|
} from '@digigov/form/validators/utils';
|
|
26
30
|
import { INT_VALIDATOR } from '@digigov/form/validators/utils/int';
|
|
27
31
|
import { NUMBER_VALIDATOR } from '@digigov/form/validators/utils/number';
|
|
28
|
-
dayjs.extend(customParseFormat);
|
|
29
|
-
|
|
30
|
-
const VALID_DATE_FORMATS = ['DD/MM/YYYY'];
|
|
31
|
-
const DATE_CACHE = {};
|
|
32
|
-
const getDate = (v) => {
|
|
33
|
-
return DATE_CACHE[v] ? DATE_CACHE[v] : dayjs(v, VALID_DATE_FORMATS, true);
|
|
34
|
-
};
|
|
35
32
|
|
|
36
33
|
export const getYUPTypeMap = (): Record<string, any> => {
|
|
37
34
|
const yupTypeMap = {
|
|
@@ -47,8 +44,28 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
47
44
|
.nullable()
|
|
48
45
|
.test(FILE_MAX_SIZE_VALIDATOR(field));
|
|
49
46
|
},
|
|
50
|
-
string: yup.
|
|
51
|
-
|
|
47
|
+
string: (field): yup.StringSchema => {
|
|
48
|
+
if (field.trim) {
|
|
49
|
+
return yup.string().trim();
|
|
50
|
+
} else {
|
|
51
|
+
return yup.string();
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
boolean: (): yup.BooleanSchema<
|
|
55
|
+
boolean | null | undefined,
|
|
56
|
+
AnyObject,
|
|
57
|
+
boolean | null | undefined
|
|
58
|
+
> => {
|
|
59
|
+
return yup
|
|
60
|
+
.boolean()
|
|
61
|
+
.nullable()
|
|
62
|
+
.transform((value) => {
|
|
63
|
+
if (value === '' || typeof value === 'string') return null;
|
|
64
|
+
if (typeof value === 'boolean') return value;
|
|
65
|
+
if (value === 0 || value === 1) return Boolean(value);
|
|
66
|
+
return value;
|
|
67
|
+
});
|
|
68
|
+
},
|
|
52
69
|
object: (
|
|
53
70
|
field
|
|
54
71
|
):
|
|
@@ -97,22 +114,42 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
97
114
|
return yup.array().of(yup.string());
|
|
98
115
|
}
|
|
99
116
|
},
|
|
117
|
+
number: (): MixedSchema =>
|
|
118
|
+
yup
|
|
119
|
+
.mixed()
|
|
120
|
+
.transform((_, val) => (val !== '' ? Number(val) : undefined))
|
|
121
|
+
.test(NUMBER_VALIDATOR()),
|
|
100
122
|
int: (): MixedSchema =>
|
|
101
123
|
yup
|
|
102
124
|
.mixed()
|
|
103
|
-
.transform((_, val) => (val !== '' ? Number(val) :
|
|
125
|
+
.transform((_, val) => (val !== '' ? Number(val) : undefined))
|
|
104
126
|
.test(NUMBER_VALIDATOR())
|
|
105
127
|
.test(INT_VALIDATOR()),
|
|
106
|
-
email: (): yup.StringSchema =>
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
128
|
+
email: (field): yup.StringSchema =>
|
|
129
|
+
field.trim
|
|
130
|
+
? yup.string().trim().email('form.error.email')
|
|
131
|
+
: yup.string().email('form.error.email'),
|
|
132
|
+
afm: (field): yup.StringSchema =>
|
|
133
|
+
field.trim
|
|
134
|
+
? yup.string().trim().test(AFM_VALIDATOR)
|
|
135
|
+
: yup.string().test(AFM_VALIDATOR),
|
|
136
|
+
uuid4: (field): yup.StringSchema =>
|
|
137
|
+
field.trim
|
|
138
|
+
? yup.string().trim().test(UUID4_VALIDATOR)
|
|
139
|
+
: yup.string().test(UUID4_VALIDATOR),
|
|
140
|
+
iban: (field): yup.StringSchema =>
|
|
141
|
+
field.trim
|
|
142
|
+
? yup.string().trim().test(IBAN_VALIDATOR(field))
|
|
143
|
+
: yup.string().trim().test(IBAN_VALIDATOR(field)),
|
|
144
|
+
otp: (field): yup.StringSchema =>
|
|
145
|
+
yup.string().trim().test(OTP_VALIDATOR(field)),
|
|
111
146
|
text: (field): yup.StringSchema => {
|
|
112
147
|
if (field?.extra?.limit?.max || !!field?.extra?.limit?.min) {
|
|
113
|
-
return
|
|
148
|
+
return field.trim
|
|
149
|
+
? yup.string().trim().test(TEXT_LIMIT_VALIDATOR(field))
|
|
150
|
+
: yup.string().test(TEXT_LIMIT_VALIDATOR(field));
|
|
114
151
|
} else {
|
|
115
|
-
return yup.string();
|
|
152
|
+
return field.trim ? yup.string().trim() : yup.string();
|
|
116
153
|
}
|
|
117
154
|
},
|
|
118
155
|
image: (field): MixedSchema => {
|
|
@@ -129,11 +166,17 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
129
166
|
.test(IMAGE_DIMENSION_VALIDATOR(field));
|
|
130
167
|
},
|
|
131
168
|
postal_code: (field): yup.StringSchema =>
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
169
|
+
field.trim
|
|
170
|
+
? yup.string().trim().test(POSTALCODE_VALIDATOR(field))
|
|
171
|
+
: yup.string().test(POSTALCODE_VALIDATOR(field)),
|
|
172
|
+
mobile_phone: (field): yup.StringSchema =>
|
|
173
|
+
field.trim
|
|
174
|
+
? yup.string().trim().test(MOBILE_PHONE_VALIDATOR)
|
|
175
|
+
: yup.string().test(MOBILE_PHONE_VALIDATOR),
|
|
135
176
|
phone_number: (field): yup.StringSchema =>
|
|
136
|
-
|
|
177
|
+
field.trim
|
|
178
|
+
? yup.string().trim().test(PHONE_NUMBER_VALIDATOR(field))
|
|
179
|
+
: yup.string().test(PHONE_NUMBER_VALIDATOR(field)),
|
|
137
180
|
'choice:multiple': (): yup.ArraySchema<
|
|
138
181
|
yup.StringSchema<string | undefined, AnyObject, string | undefined>,
|
|
139
182
|
AnyObject,
|
|
@@ -145,69 +188,32 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
145
188
|
AnyObject,
|
|
146
189
|
string | null | undefined
|
|
147
190
|
> => yup.string().nullable(),
|
|
148
|
-
date: (
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if (params.max) {
|
|
159
|
-
let maxDate;
|
|
160
|
-
if (params.max === 'now') {
|
|
161
|
-
const today = new Date();
|
|
162
|
-
maxDate = new Date(today);
|
|
163
|
-
} else {
|
|
164
|
-
maxDate = getDate(params.max).toDate();
|
|
165
|
-
}
|
|
166
|
-
const maxNextDate = new Date(maxDate);
|
|
167
|
-
maxNextDate.setDate(maxDate.getDate() + 1);
|
|
168
|
-
simpleDate = simpleDate.test({
|
|
169
|
-
name: 'earlier-than',
|
|
170
|
-
message: {
|
|
171
|
-
key: 'form.error.date.earlier_than',
|
|
172
|
-
context: {
|
|
173
|
-
maxDate: maxNextDate.toLocaleDateString(),
|
|
174
|
-
},
|
|
175
|
-
},
|
|
176
|
-
test: function (value) {
|
|
177
|
-
if (!value) return true;
|
|
178
|
-
const date = getDate(value);
|
|
179
|
-
const isValid = +date.toDate() < +maxDate;
|
|
180
|
-
return isValid;
|
|
181
|
-
},
|
|
182
|
-
});
|
|
191
|
+
date: (
|
|
192
|
+
field
|
|
193
|
+
): yup.StringSchema<
|
|
194
|
+
string | null | undefined,
|
|
195
|
+
AnyObject,
|
|
196
|
+
string | null | undefined
|
|
197
|
+
> => {
|
|
198
|
+
let schema = yup.string().nullable();
|
|
199
|
+
if (field?.extra?.min) {
|
|
200
|
+
schema = schema.test(LATER_THAN_VALIDATOR(field));
|
|
183
201
|
}
|
|
184
|
-
if (
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
key: 'form.error.date.later_than',
|
|
198
|
-
context: {
|
|
199
|
-
minDate: minPreviousDate.toLocaleDateString(),
|
|
200
|
-
},
|
|
201
|
-
},
|
|
202
|
-
test: function (value) {
|
|
203
|
-
if (!value) return true;
|
|
204
|
-
const date = getDate(value);
|
|
205
|
-
const isValid = +date.toDate() > +minDate;
|
|
206
|
-
return isValid;
|
|
207
|
-
},
|
|
208
|
-
});
|
|
202
|
+
if (field?.extra?.max) {
|
|
203
|
+
schema = schema.test(EARLIER_THAN_VALIDATOR(field));
|
|
204
|
+
} else {
|
|
205
|
+
schema = schema.test(DATE_VALIDATOR);
|
|
206
|
+
}
|
|
207
|
+
return schema;
|
|
208
|
+
},
|
|
209
|
+
datetime: (field): yup.StringSchema => {
|
|
210
|
+
if (field?.extra?.min) {
|
|
211
|
+
return yup.string().test(LATER_THAN_DATETIME_VALIDATOR(field));
|
|
212
|
+
}
|
|
213
|
+
if (field?.extra?.max) {
|
|
214
|
+
return yup.string().test(EARLIER_THAN_DATETIME_VALIDATOR(field));
|
|
209
215
|
}
|
|
210
|
-
return
|
|
216
|
+
return yup.string().test(DATETIME_VALIDATOR);
|
|
211
217
|
},
|
|
212
218
|
};
|
|
213
219
|
return yupTypeMap;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
3
|
+
import { FieldSpec } from '@digigov/form/types';
|
|
4
|
+
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
5
|
+
|
|
6
|
+
dayjs.extend(customParseFormat);
|
|
7
|
+
|
|
8
|
+
const VALID_DATE_FORMATS = ['DD/MM/YYYY'];
|
|
9
|
+
const DATE_CACHE = {};
|
|
10
|
+
|
|
11
|
+
const getDate = (v: string) => {
|
|
12
|
+
return DATE_CACHE[v] ? DATE_CACHE[v] : dayjs(v, VALID_DATE_FORMATS, true);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// Function to check partial date completion
|
|
16
|
+
const checkPartialDate = (value: string) => {
|
|
17
|
+
console.log("value.split('/')", value.split('/'));
|
|
18
|
+
const [day, month, year] = value.split('/');
|
|
19
|
+
if (day && !month && !year) {
|
|
20
|
+
return 'form.error.date.invalid_month_year';
|
|
21
|
+
}
|
|
22
|
+
if (!day && month && !year) {
|
|
23
|
+
return 'form.error.date.invalid_day_year';
|
|
24
|
+
}
|
|
25
|
+
if (!day && !month && year) {
|
|
26
|
+
return 'form.error.date.invalid_day_month';
|
|
27
|
+
}
|
|
28
|
+
if (day && month && !year) {
|
|
29
|
+
return 'form.error.date.invalid_year';
|
|
30
|
+
}
|
|
31
|
+
if (day && !month && year) {
|
|
32
|
+
return 'form.error.date.invalid_month';
|
|
33
|
+
}
|
|
34
|
+
if (!day && month && year) {
|
|
35
|
+
return 'form.error.date.invalid_day';
|
|
36
|
+
} else {
|
|
37
|
+
return 'form.error.date.invalid';
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const LATER_THAN_VALIDATOR = (field: FieldSpec): ValidatorSchema => {
|
|
42
|
+
let minDate;
|
|
43
|
+
const params = field.extra || {};
|
|
44
|
+
if (params.min === 'now') {
|
|
45
|
+
const today = new Date();
|
|
46
|
+
minDate = new Date(today);
|
|
47
|
+
} else {
|
|
48
|
+
minDate = getDate(params.min).toDate();
|
|
49
|
+
}
|
|
50
|
+
const minPreviousDate = new Date(minDate);
|
|
51
|
+
minPreviousDate.setDate(minDate.getDate() - 1);
|
|
52
|
+
return {
|
|
53
|
+
name: 'later-than',
|
|
54
|
+
message: {
|
|
55
|
+
key: 'form.error.date.later_than',
|
|
56
|
+
context: {
|
|
57
|
+
minDate: minPreviousDate.toLocaleDateString(),
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
test: function (value: string) {
|
|
61
|
+
if (!value) return true;
|
|
62
|
+
const date = getDate(value);
|
|
63
|
+
const isValid = +date.toDate() > +minDate;
|
|
64
|
+
return isValid;
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export const EARLIER_THAN_VALIDATOR = (field: FieldSpec): ValidatorSchema => {
|
|
70
|
+
let maxDate;
|
|
71
|
+
const params = field.extra || {};
|
|
72
|
+
if (params.max === 'now') {
|
|
73
|
+
const today = new Date();
|
|
74
|
+
maxDate = new Date(today);
|
|
75
|
+
} else {
|
|
76
|
+
maxDate = getDate(params.max).toDate();
|
|
77
|
+
}
|
|
78
|
+
const maxNextDate = new Date(maxDate);
|
|
79
|
+
maxNextDate.setDate(maxDate.getDate() + 1);
|
|
80
|
+
return {
|
|
81
|
+
name: 'earlier-than',
|
|
82
|
+
message: {
|
|
83
|
+
key: 'form.error.date.earlier_than',
|
|
84
|
+
context: {
|
|
85
|
+
maxDate: maxNextDate.toLocaleDateString(),
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
test: function (value: string) {
|
|
89
|
+
if (!value) return true;
|
|
90
|
+
const date = getDate(value);
|
|
91
|
+
const isValid = +date.toDate() < +maxDate;
|
|
92
|
+
return isValid;
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export const DATE_VALIDATOR = {
|
|
98
|
+
name: 'date-validator',
|
|
99
|
+
message: (v): string => {
|
|
100
|
+
return checkPartialDate(v.value);
|
|
101
|
+
},
|
|
102
|
+
test: function (value: string) {
|
|
103
|
+
if (!value) return true;
|
|
104
|
+
const date = getDate(value);
|
|
105
|
+
return date.isValid();
|
|
106
|
+
},
|
|
107
|
+
};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
3
|
+
import { FieldSpec } from '@digigov/form/types';
|
|
4
|
+
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
5
|
+
|
|
6
|
+
dayjs.extend(customParseFormat);
|
|
7
|
+
|
|
8
|
+
const VALID_DATETIME_FORMATS = ['DD/MM/YYYY HH:mm'];
|
|
9
|
+
const DATETIME_CACHE = {};
|
|
10
|
+
|
|
11
|
+
const getDateTime = (v: string) => {
|
|
12
|
+
return DATETIME_CACHE[v]
|
|
13
|
+
? DATETIME_CACHE[v]
|
|
14
|
+
: dayjs(v, VALID_DATETIME_FORMATS, true);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// Function to check partial datetime completion
|
|
18
|
+
const checkPartialDateTime = (value: string) => {
|
|
19
|
+
const [datePart, timePart] = value.split(' ');
|
|
20
|
+
const [day, month, year] = datePart.split('/');
|
|
21
|
+
const [hours, minutes] = timePart ? timePart.split(':') : [null, null];
|
|
22
|
+
|
|
23
|
+
// Check date part first
|
|
24
|
+
if (day && !month && !year) {
|
|
25
|
+
return 'form.error.datetime.invalid_month_year';
|
|
26
|
+
}
|
|
27
|
+
if (!day && month && !year) {
|
|
28
|
+
return 'form.error.datetime.invalid_day_year';
|
|
29
|
+
}
|
|
30
|
+
if (!day && !month && year) {
|
|
31
|
+
return 'form.error.datetime.invalid_day_month';
|
|
32
|
+
}
|
|
33
|
+
if (day && month && !year) {
|
|
34
|
+
return 'form.error.datetime.invalid_year';
|
|
35
|
+
}
|
|
36
|
+
if (day && !month && year) {
|
|
37
|
+
return 'form.error.datetime.invalid_month';
|
|
38
|
+
}
|
|
39
|
+
if (!day && month && year) {
|
|
40
|
+
return 'form.error.datetime.invalid_day';
|
|
41
|
+
}
|
|
42
|
+
// If date is complete, check time part
|
|
43
|
+
if (day && month && year) {
|
|
44
|
+
if (hours && !minutes) {
|
|
45
|
+
return 'form.error.datetime.invalid_minutes';
|
|
46
|
+
}
|
|
47
|
+
if (!hours && minutes) {
|
|
48
|
+
return 'form.error.datetime.invalid_hours';
|
|
49
|
+
}
|
|
50
|
+
if (!hours && !minutes) {
|
|
51
|
+
return 'form.error.datetime.invalid';
|
|
52
|
+
}
|
|
53
|
+
if (hours && minutes) {
|
|
54
|
+
const hoursNum = parseInt(hours);
|
|
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
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return 'form.error.datetime.invalid';
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const LATER_THAN_DATETIME_VALIDATOR = (
|
|
69
|
+
field: FieldSpec
|
|
70
|
+
): ValidatorSchema => {
|
|
71
|
+
let minDateTime;
|
|
72
|
+
const params = field.extra || {};
|
|
73
|
+
if (params.min === 'now') {
|
|
74
|
+
minDateTime = dayjs();
|
|
75
|
+
} else {
|
|
76
|
+
minDateTime = getDateTime(params.min);
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
name: 'later-than-datetime',
|
|
80
|
+
message: {
|
|
81
|
+
key: 'form.error.datetime.later_than',
|
|
82
|
+
context: {
|
|
83
|
+
minDateTime: minDateTime.format('DD/MM/YYYY HH:mm'),
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
test: function (value: string) {
|
|
87
|
+
if (!value) return true;
|
|
88
|
+
const datetime = getDateTime(value);
|
|
89
|
+
return datetime.isValid() && datetime.isAfter(minDateTime);
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export const EARLIER_THAN_DATETIME_VALIDATOR = (
|
|
95
|
+
field: FieldSpec
|
|
96
|
+
): ValidatorSchema => {
|
|
97
|
+
let maxDateTime;
|
|
98
|
+
const params = field.extra || {};
|
|
99
|
+
if (params.max === 'now') {
|
|
100
|
+
maxDateTime = dayjs();
|
|
101
|
+
} else {
|
|
102
|
+
maxDateTime = getDateTime(params.max);
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
name: 'earlier-than-datetime',
|
|
106
|
+
message: {
|
|
107
|
+
key: 'form.error.datetime.earlier_than',
|
|
108
|
+
context: {
|
|
109
|
+
maxDateTime: maxDateTime.format('DD/MM/YYYY HH:mm'),
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
test: function (value: string) {
|
|
113
|
+
if (!value) return true;
|
|
114
|
+
const datetime = getDateTime(value);
|
|
115
|
+
return datetime.isValid() && datetime.isBefore(maxDateTime);
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export const DATETIME_VALIDATOR = {
|
|
121
|
+
name: 'datetime-validator',
|
|
122
|
+
message: (v): string => {
|
|
123
|
+
return checkPartialDateTime(v.value);
|
|
124
|
+
},
|
|
125
|
+
test: function (value: string) {
|
|
126
|
+
if (!value) return true;
|
|
127
|
+
const datetime = getDateTime(value);
|
|
128
|
+
return datetime.isValid();
|
|
129
|
+
},
|
|
130
|
+
};
|
|
@@ -5,17 +5,19 @@ const DEFAULT_FILE_MAX_SIZE = 10000000;
|
|
|
5
5
|
|
|
6
6
|
export const FILE_MAX_SIZE_VALIDATOR = (field: FieldSpec): ValidatorSchema => ({
|
|
7
7
|
name: 'file-max-size-validator',
|
|
8
|
-
message:
|
|
8
|
+
message: {
|
|
9
|
+
key:
|
|
10
|
+
field.type === 'file' ? 'form.error.file_size' : 'form.error.image_size',
|
|
11
|
+
context: {
|
|
12
|
+
maxSizeToMb:
|
|
13
|
+
(field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE) / 1000000,
|
|
14
|
+
},
|
|
15
|
+
},
|
|
9
16
|
test: (value: File[]): boolean => {
|
|
10
|
-
if (
|
|
11
|
-
for (const file of value) {
|
|
12
|
-
if (file.size >= field.extra.limit.maxSize) {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
} else if (value) {
|
|
17
|
+
if (value) {
|
|
17
18
|
for (const file of value) {
|
|
18
|
-
|
|
19
|
+
const maxSize = field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE;
|
|
20
|
+
if (file.size > maxSize) {
|
|
19
21
|
return false;
|
|
20
22
|
}
|
|
21
23
|
}
|
|
@@ -11,6 +11,8 @@ export * from '@digigov/form/validators/utils/phone';
|
|
|
11
11
|
export * from '@digigov/form/validators/utils/postal_code';
|
|
12
12
|
export * from '@digigov/form/validators/utils/uuid4';
|
|
13
13
|
export * from '@digigov/form/validators/utils/text_limit';
|
|
14
|
+
export * from '@digigov/form/validators/utils/date';
|
|
15
|
+
export * from '@digigov/form/validators/utils/datetime';
|
|
14
16
|
|
|
15
17
|
export function getYupField(field: FieldSpec, yupTypeMap: Record<string, any>) {
|
|
16
18
|
const yupField = yupTypeMap[field?.type || 'string'] || yupTypeMap['string'];
|
|
@@ -13,7 +13,7 @@ export const INT_VALIDATOR = (): ValidatorSchema => {
|
|
|
13
13
|
name: 'int-validator',
|
|
14
14
|
message: 'form.error.positive_integer_number',
|
|
15
15
|
test: (value: number): boolean => {
|
|
16
|
-
if (value ===
|
|
16
|
+
if (value === undefined) {
|
|
17
17
|
return true;
|
|
18
18
|
}
|
|
19
19
|
return validateIntNumber(value);
|
|
@@ -9,7 +9,7 @@ export const NUMBER_VALIDATOR = (): ValidatorSchema => {
|
|
|
9
9
|
name: 'number-validator',
|
|
10
10
|
message: 'form.error.number',
|
|
11
11
|
test: (value: number): boolean => {
|
|
12
|
-
if (value ===
|
|
12
|
+
if (value === undefined) {
|
|
13
13
|
return true;
|
|
14
14
|
}
|
|
15
15
|
return validateNumber(value);
|