@digigov/form 2.0.0-8e254888 → 2.0.0-a0ac149e
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.d.ts +3 -3
- package/Field/ErrorGroup.js.map +1 -1
- package/Field/FieldBase/index.js +7 -4
- package/Field/FieldBase.d.ts +1 -1
- package/Field/FieldBase.js.map +2 -2
- package/Field/FieldBaseContainer/index.js +37 -18
- 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 +25 -29
- package/Field/index.js.map +2 -2
- package/Field/types.d.ts +21 -12
- package/Field/utils/evaluateFieldWithConditions.d.ts +2 -2
- package/Field/utils/evaluateFieldWithConditions.js.map +2 -2
- package/Field/utils/resolveField/index.js +35 -0
- package/Field/utils/{calculateField → resolveField}/package.json +1 -1
- package/Field/utils/resolveField.d.ts +3 -0
- package/Field/utils/resolveField.js.map +7 -0
- package/Field/utils/useField/index.js +12 -3
- package/Field/utils/useField.d.ts +1 -1
- package/Field/utils/useField.js.map +2 -2
- package/FieldArray/BaseFieldArray/index.js +76 -0
- package/FieldArray/BaseFieldArray/package.json +6 -0
- package/FieldArray/BaseFieldArray.d.ts +5 -0
- package/FieldArray/BaseFieldArray.js.map +7 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayDisplay.stories.d.ts +10 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay/index.js +97 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay/package.json +6 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay.d.ts +22 -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__/Default.d.ts +2 -0
- package/FieldArray/FormDialog/ArrayDisplay/__stories__/ReadOnly.d.ts +2 -0
- package/FieldArray/FormDialog/ArrayDisplay/__stories__/Sortable.d.ts +2 -0
- package/FieldArray/FormDialog/ArrayDisplay/index.d.ts +14 -0
- package/FieldArray/FormDialog/ArrayDisplay/index.js +51 -0
- package/FieldArray/FormDialog/ArrayDisplay/index.js.map +7 -0
- package/{inputs/Input/inputsInputScenarios → FieldArray/FormDialog/ArrayDisplay}/package.json +1 -1
- package/FieldArray/FormDialog/ArrayEditModal/index.js +149 -0
- package/FieldArray/FormDialog/ArrayEditModal/package.json +6 -0
- package/FieldArray/FormDialog/ArrayEditModal.d.ts +26 -0
- package/FieldArray/FormDialog/ArrayEditModal.js.map +7 -0
- package/FieldArray/FormDialog/index.d.ts +19 -0
- package/FieldArray/FormDialog/index.js +172 -258
- package/FieldArray/FormDialog/index.js.map +7 -0
- package/FieldArray/__stories__/Default.d.ts +1 -1
- package/FieldArray/__stories__/WithExactLength.d.ts +1 -1
- package/FieldArray/__stories__/WithModal.d.ts +1 -1
- package/FieldArray/index.d.ts +5 -2
- package/FieldArray/index.js +36 -57
- package/FieldArray/index.js.map +2 -2
- package/FieldObject/index.d.ts +7 -4
- package/FieldObject/index.js +30 -26
- 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 +2 -0
- package/FormBuilder/__stories__/AutoErrorGrouping.d.ts +1 -1
- package/FormBuilder/__stories__/Default.d.ts +1 -1
- package/FormBuilder/__stories__/ErrorGrouping.d.ts +1 -1
- package/FormBuilder/index.d.ts +2 -2
- package/FormBuilder/index.js +163 -134
- package/FormBuilder/index.js.map +2 -2
- package/FormContext/index.js +6 -2
- package/FormContext.d.ts +3 -2
- package/FormContext.js.map +2 -2
- package/MultiplicityField/MultiplicityField.stories.d.ts +2 -0
- package/MultiplicityField/__stories__/Default.d.ts +1 -1
- package/MultiplicityField/__stories__/PreviewDisplay.d.ts +1 -1
- package/MultiplicityField/__stories__/WithExactLength.d.ts +1 -1
- package/MultiplicityField/__stories__/WithMaxLength.d.ts +1 -1
- package/MultiplicityField/__stories__/WithMinAndMaxLength.d.ts +1 -1
- package/MultiplicityField/__stories__/WithMinLength.d.ts +1 -1
- package/MultiplicityField/add-objects/index.js +12 -19
- package/MultiplicityField/add-objects.d.ts +1 -1
- package/MultiplicityField/add-objects.js.map +2 -2
- package/MultiplicityField/index.d.ts +2 -2
- package/MultiplicityField/index.js +4 -1
- package/MultiplicityField/index.js.map +2 -2
- package/MultiplicityField/types.d.ts +3 -2
- package/Questions/Questions.d.ts +1 -1
- package/Questions/Questions.js.map +1 -1
- package/Questions/Questions.stories.d.ts +2 -0
- package/Questions/QuestionsContext.d.ts +1 -1
- package/Questions/QuestionsContext.js.map +1 -1
- package/Questions/Step/Step.d.ts +1 -1
- package/Questions/Step/Step.js.map +1 -1
- package/Questions/Step/StepArrayReview.d.ts +1 -1
- package/Questions/Step/StepArrayReview.js.map +1 -1
- package/Questions/Step/StepContext.d.ts +1 -1
- package/Questions/Step/StepContext.js.map +1 -1
- package/Questions/Step/StepDescription.d.ts +1 -1
- package/Questions/Step/StepDescription.js.map +2 -2
- package/Questions/Step/StepForm.d.ts +2 -2
- package/Questions/Step/StepForm.js.map +1 -1
- package/Questions/Step/StepQuote.d.ts +1 -1
- package/Questions/Step/StepQuote.js.map +2 -2
- package/Questions/Step/StepTitle.d.ts +1 -1
- package/Questions/Step/StepTitle.js.map +2 -2
- package/Questions/Step/getAddMoreFields.d.ts +2 -2
- package/Questions/Step/getAddMoreFields.js.map +1 -1
- package/Questions/Step/types.d.ts +1 -1
- package/Questions/__stories__/Default.d.ts +1 -1
- package/Questions/getNextStep.d.ts +1 -1
- package/Questions/getNextStep.js.map +1 -1
- package/Questions/types.d.ts +1 -1
- package/cjs/Field/ErrorGroup.js.map +1 -1
- package/cjs/Field/FieldBase/index.js +7 -4
- package/cjs/Field/FieldBase.js.map +2 -2
- package/cjs/Field/FieldBaseContainer/index.js +36 -17
- package/cjs/Field/FieldBaseContainer.js.map +3 -3
- package/cjs/Field/FieldConditional/index.js +4 -0
- package/cjs/Field/FieldConditional.js.map +2 -2
- package/cjs/Field/index.js +25 -26
- package/cjs/Field/index.js.map +2 -2
- package/cjs/Field/types.js.map +1 -1
- package/cjs/Field/utils/evaluateFieldWithConditions.js.map +2 -2
- package/cjs/Field/utils/resolveField/index.js +55 -0
- package/cjs/Field/utils/resolveField.js.map +7 -0
- package/cjs/Field/utils/useField/index.js +12 -3
- package/cjs/Field/utils/useField.js.map +2 -2
- package/cjs/FieldArray/BaseFieldArray/index.js +109 -0
- package/cjs/FieldArray/BaseFieldArray.js.map +7 -0
- package/cjs/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay/index.js +130 -0
- package/cjs/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay.js.map +7 -0
- package/cjs/{locales/el → FieldArray/FormDialog/ArrayDisplay/ArrayItemHeader}/index.js +16 -7
- package/cjs/FieldArray/FormDialog/ArrayDisplay/ArrayItemHeader.js.map +7 -0
- package/cjs/FieldArray/FormDialog/ArrayDisplay/index.js +84 -0
- package/cjs/FieldArray/FormDialog/ArrayDisplay/index.js.map +7 -0
- package/cjs/FieldArray/FormDialog/ArrayEditModal/index.js +177 -0
- package/cjs/FieldArray/FormDialog/ArrayEditModal.js.map +7 -0
- package/cjs/FieldArray/FormDialog/index.js +163 -244
- package/cjs/FieldArray/FormDialog/index.js.map +7 -0
- package/cjs/FieldArray/index.js +35 -56
- package/cjs/FieldArray/index.js.map +3 -3
- package/cjs/FieldObject/index.js +30 -23
- 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 +164 -135
- package/cjs/FormBuilder/index.js.map +3 -3
- package/cjs/FormContext/index.js +7 -2
- package/cjs/FormContext.js.map +2 -2
- package/cjs/MultiplicityField/add-objects/index.js +11 -13
- package/cjs/MultiplicityField/add-objects.js.map +2 -2
- package/cjs/MultiplicityField/index.js +4 -1
- package/cjs/MultiplicityField/index.js.map +2 -2
- package/cjs/MultiplicityField/types.js.map +1 -1
- package/cjs/Questions/Questions.js.map +1 -1
- package/cjs/Questions/QuestionsContext.js.map +1 -1
- package/cjs/Questions/Step/Step.js.map +1 -1
- package/cjs/Questions/Step/StepArrayReview.js.map +1 -1
- package/cjs/Questions/Step/StepContext.js.map +1 -1
- package/cjs/Questions/Step/StepDescription.js.map +2 -2
- package/cjs/Questions/Step/StepForm.js.map +1 -1
- package/cjs/Questions/Step/StepQuote.js.map +2 -2
- package/cjs/Questions/Step/StepTitle.js.map +2 -2
- package/cjs/Questions/Step/getAddMoreFields.js.map +1 -1
- package/cjs/Questions/Step/types.js.map +1 -1
- package/cjs/Questions/getNextStep.js.map +1 -1
- package/cjs/Questions/types.js.map +1 -1
- package/cjs/hooks/useFieldFocusManager/index.js +135 -0
- package/cjs/hooks/useFieldFocusManager.js.map +7 -0
- package/cjs/hooks/utils/index.js +98 -0
- package/cjs/hooks/utils.js.map +7 -0
- package/cjs/inputs/AutoCompleteInput/index.js.map +2 -2
- package/cjs/inputs/Checkboxes/index.js +67 -63
- package/cjs/inputs/Checkboxes/index.js.map +2 -2
- package/cjs/inputs/DateInput/index.js +51 -19
- package/cjs/inputs/DateInput/index.js.map +2 -2
- package/cjs/inputs/DateTimeInput/index.js +78 -39
- package/cjs/inputs/DateTimeInput/index.js.map +2 -2
- package/cjs/inputs/FileInput/index.js +52 -29
- 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 +41 -10
- package/cjs/inputs/ImageInput/index.js.map +2 -2
- package/cjs/inputs/Input/index.js +55 -57
- package/cjs/inputs/Input/index.js.map +2 -2
- package/cjs/inputs/Label/index.js.map +1 -1
- package/cjs/inputs/OtpInput/index.js +36 -31
- package/cjs/inputs/OtpInput/index.js.map +2 -2
- package/cjs/inputs/Radio/index.js +5 -4
- package/cjs/inputs/Radio/index.js.map +3 -3
- package/cjs/inputs/Select/index.js +4 -3
- package/cjs/inputs/Select/index.js.map +2 -2
- package/cjs/{Field/utils → inputs/registry}/index.js +7 -5
- package/cjs/inputs/registry.js.map +7 -0
- package/cjs/{lazy/index.js → lazy.js} +12 -10
- package/cjs/lazy.js.map +2 -2
- package/cjs/{registry/index.js → registry.js} +25 -15
- package/cjs/registry.js.map +2 -2
- package/cjs/types.js.map +1 -1
- package/cjs/utils/index.js +20 -6
- package/cjs/utils.js.map +2 -2
- package/cjs/validators/index.js +11 -6
- package/cjs/validators/index.js.map +2 -2
- package/cjs/validators/types.js.map +1 -1
- package/cjs/validators/utils/amka/index.js +60 -0
- package/cjs/validators/utils/amka.js.map +7 -0
- package/cjs/validators/utils/date/index.js +26 -3
- package/cjs/validators/utils/date.js.map +2 -2
- package/cjs/validators/utils/datetime/index.js +118 -24
- package/cjs/validators/utils/datetime.js.map +2 -2
- package/cjs/validators/utils/file/index.js +30 -17
- package/cjs/validators/utils/file.js.map +2 -2
- package/cjs/validators/utils/iban.js.map +1 -1
- package/cjs/validators/utils/image.js.map +1 -1
- package/cjs/validators/utils/index.js +5 -1
- package/cjs/validators/utils/index.js.map +2 -2
- package/cjs/validators/utils/int.js.map +1 -1
- package/cjs/validators/utils/number.js.map +1 -1
- package/cjs/validators/utils/otp.js.map +1 -1
- package/cjs/validators/utils/phone.js.map +1 -1
- package/cjs/validators/utils/postal_code.js.map +1 -1
- package/cjs/validators/utils/text_limit.js.map +1 -1
- package/hooks/useFieldFocusManager/index.js +116 -0
- package/hooks/useFieldFocusManager/package.json +6 -0
- package/hooks/useFieldFocusManager.d.ts +25 -0
- package/hooks/useFieldFocusManager.js.map +7 -0
- package/hooks/utils/index.js +73 -0
- package/{Field → hooks}/utils/package.json +1 -1
- package/hooks/utils.d.ts +18 -0
- package/hooks/utils.js.map +7 -0
- package/index.js +1 -1
- package/inputs/AutoCompleteInput/AutoComplete.stories.d.ts +2 -0
- package/inputs/AutoCompleteInput/__stories__/Default.d.ts +1 -1
- package/inputs/AutoCompleteInput/__stories__/Multiple.d.ts +1 -1
- package/inputs/AutoCompleteInput/index.d.ts +3 -3
- package/inputs/AutoCompleteInput/index.js +1 -3
- package/inputs/AutoCompleteInput/index.js.map +2 -2
- package/inputs/Checkboxes/Checkboxes.stories.d.ts +2 -0
- package/inputs/Checkboxes/__stories__/Conditional.d.ts +1 -1
- package/inputs/Checkboxes/__stories__/Default.d.ts +1 -1
- package/inputs/Checkboxes/__stories__/WithDivider.d.ts +1 -1
- package/inputs/Checkboxes/index.d.ts +3 -3
- package/inputs/Checkboxes/index.js +67 -63
- package/inputs/Checkboxes/index.js.map +2 -2
- package/inputs/DateInput/DateInput.stories.d.ts +6 -0
- package/inputs/DateInput/__stories__/Default.d.ts +1 -1
- package/inputs/DateInput/__stories__/WithDefaultValue.d.ts +3 -0
- package/inputs/DateInput/__stories__/WithInitialValue.d.ts +3 -0
- package/inputs/DateInput/__stories__/WithWrongDefaultValue.d.ts +3 -0
- package/inputs/DateInput/__stories__/WithWrongInitialValue.d.ts +3 -0
- package/inputs/DateInput/index.d.ts +2 -5
- package/inputs/DateInput/index.js +52 -20
- package/inputs/DateInput/index.js.map +2 -2
- package/inputs/DateTimeInput/DateTimeInput.stories.d.ts +10 -3
- package/inputs/DateTimeInput/__stories__/Default.d.ts +1 -1
- package/inputs/DateTimeInput/__stories__/WithDefaultValue.d.ts +3 -0
- package/inputs/DateTimeInput/__stories__/WithInitialValue.d.ts +3 -0
- package/inputs/DateTimeInput/__stories__/WithWrongDefaultValue.d.ts +3 -0
- package/inputs/DateTimeInput/__stories__/WithWrongInitialValue.d.ts +3 -0
- package/inputs/DateTimeInput/index.d.ts +2 -5
- package/inputs/DateTimeInput/index.js +79 -40
- package/inputs/DateTimeInput/index.js.map +2 -2
- package/inputs/FileInput/FileInput.stories.d.ts +3 -0
- package/inputs/FileInput/__stories__/Default.d.ts +1 -1
- package/inputs/FileInput/__stories__/WithBorderAndLink.d.ts +3 -0
- package/inputs/FileInput/index.d.ts +12 -5
- package/inputs/FileInput/index.js +53 -30
- package/inputs/FileInput/index.js.map +2 -2
- package/inputs/ImageInput/ImageInput.stories.d.ts +4 -1
- package/inputs/ImageInput/__stories__/Default.d.ts +1 -1
- package/inputs/ImageInput/__stories__/MaxSize.d.ts +1 -1
- package/inputs/ImageInput/__stories__/WithInitialValues.d.ts +3 -0
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension.d.ts +1 -1
- package/inputs/ImageInput/__stories__/logo.d/index.js +1 -0
- package/inputs/ImageInput/__stories__/logo.d/package.json +6 -0
- package/inputs/ImageInput/__stories__/logo.d.js.map +7 -0
- package/inputs/ImageInput/index.d.ts +10 -2
- package/inputs/ImageInput/index.js +42 -11
- package/inputs/ImageInput/index.js.map +2 -2
- package/inputs/Input/Input.stories.d.ts +4 -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 +1 -1
- package/inputs/Input/__stories__/TextWithLimit.d.ts +1 -1
- package/inputs/Input/index.d.ts +4 -3
- package/inputs/Input/index.js +55 -57
- package/inputs/Input/index.js.map +2 -2
- package/inputs/Label/Label.stories.d.ts +2 -0
- package/inputs/Label/__stories__/Default.d.ts +1 -1
- package/inputs/Label/index.d.ts +1 -1
- package/inputs/Label/index.js.map +1 -1
- package/inputs/OtpInput/OtpInput.stories.d.ts +2 -0
- package/inputs/OtpInput/__stories__/Default.d.ts +1 -1
- package/inputs/OtpInput/index.d.ts +1 -5
- package/inputs/OtpInput/index.js +36 -31
- package/inputs/OtpInput/index.js.map +2 -2
- package/inputs/Radio/Radio.stories.d.ts +2 -0
- package/inputs/Radio/__stories__/Conditional.d.ts +1 -1
- package/inputs/Radio/__stories__/Default.d.ts +1 -1
- package/inputs/Radio/__stories__/WithDivider.d.ts +1 -1
- package/inputs/Radio/index.d.ts +4 -4
- package/inputs/Radio/index.js +5 -4
- package/inputs/Radio/index.js.map +3 -3
- package/inputs/Select/Select.stories.d.ts +2 -0
- package/inputs/Select/__stories__/Default.d.ts +1 -1
- package/inputs/Select/index.d.ts +4 -3
- package/inputs/Select/index.js +4 -3
- package/inputs/Select/index.js.map +2 -2
- package/{Field/utils → inputs/registry}/index.js +4 -2
- package/{locales/el → inputs/registry}/package.json +1 -1
- package/{Field/utils/index.d.ts → inputs/registry.d.ts} +2 -1
- package/inputs/registry.js.map +7 -0
- package/lazy/index.js +12 -10
- package/package.json +8 -8
- package/registry/index.js +25 -15
- package/src/Field/ErrorGroup.tsx +3 -3
- package/src/Field/FieldBase.tsx +7 -4
- package/src/Field/FieldBaseContainer.tsx +69 -48
- package/src/Field/FieldConditional.tsx +5 -1
- package/src/Field/doc.mdx +202 -1
- package/src/Field/index.tsx +30 -38
- package/src/Field/types.tsx +22 -14
- package/src/Field/utils/evaluateFieldWithConditions.ts +5 -2
- package/src/Field/utils/resolveField.ts +58 -0
- package/src/Field/utils/useField.ts +12 -2
- package/src/FieldArray/BaseFieldArray.tsx +97 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/ArrayDisplay.stories.js +11 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay.tsx +165 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/ArrayItemHeader.tsx +15 -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__/Sortable.tsx +93 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/index.tsx +75 -0
- package/src/FieldArray/FormDialog/ArrayEditModal.tsx +233 -0
- package/src/FieldArray/FormDialog/index.tsx +250 -0
- package/src/FieldArray/__stories__/Default.tsx +1 -1
- package/src/FieldArray/__stories__/WithExactLength.tsx +1 -1
- package/src/FieldArray/__stories__/WithModal.tsx +4 -3
- 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 +4 -0
- package/src/FieldArray/index.tsx +41 -72
- package/src/FieldObject/index.tsx +40 -33
- 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 +3 -0
- package/src/FormBuilder/__stories__/AutoErrorGrouping.tsx +1 -1
- package/src/FormBuilder/__stories__/Default.tsx +1 -1
- package/src/FormBuilder/__stories__/ErrorGrouping.tsx +1 -1
- package/src/FormBuilder/doc.mdx +9 -4
- package/src/FormBuilder/index.test.tsx +4 -0
- package/src/FormBuilder/index.tsx +197 -146
- package/src/FormBuilder/interaction.test.tsx +8 -0
- package/src/FormBuilder/scenarios.test.tsx +766 -8
- package/src/FormContext.tsx +7 -2
- package/src/MultiplicityField/MultiplicityField.stories.js +3 -0
- package/src/MultiplicityField/__stories__/Default.tsx +1 -1
- package/src/MultiplicityField/__stories__/PreviewDisplay.tsx +1 -1
- package/src/MultiplicityField/__stories__/WithExactLength.tsx +1 -1
- package/src/MultiplicityField/__stories__/WithMaxLength.tsx +1 -1
- package/src/MultiplicityField/__stories__/WithMinAndMaxLength.tsx +1 -1
- package/src/MultiplicityField/__stories__/WithMinLength.tsx +1 -1
- package/src/MultiplicityField/add-objects.tsx +14 -21
- package/src/MultiplicityField/doc.mdx +101 -83
- package/src/MultiplicityField/index.test.tsx +4 -0
- package/src/MultiplicityField/index.tsx +6 -2
- package/src/MultiplicityField/types.ts +6 -2
- package/src/Questions/Questions.stories.js +3 -0
- package/src/Questions/Questions.tsx +2 -2
- package/src/Questions/QuestionsContext.tsx +1 -1
- package/src/Questions/Step/Step.tsx +1 -1
- package/src/Questions/Step/StepArrayReview.tsx +2 -2
- package/src/Questions/Step/StepContext.tsx +1 -1
- package/src/Questions/Step/StepDescription.tsx +2 -1
- package/src/Questions/Step/StepForm.tsx +2 -2
- package/src/Questions/Step/StepQuote.tsx +2 -1
- package/src/Questions/Step/StepTitle.tsx +2 -1
- package/src/Questions/Step/getAddMoreFields.tsx +2 -2
- package/src/Questions/Step/types.tsx +1 -1
- package/src/Questions/__snapshots__/index.spec.tsx.snap +2 -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.test.tsx +4 -0
- package/src/Questions/types.tsx +1 -1
- package/src/doc.mdx +26 -11
- package/src/hooks/__tests__/useFieldFocusManager.spec.tsx +1079 -0
- package/src/hooks/__tests__/utils.spec.ts +568 -0
- package/src/hooks/useFieldFocusManager.ts +162 -0
- package/src/hooks/utils.ts +122 -0
- package/src/inputs/AutoCompleteInput/AutoComplete.stories.js +3 -0
- package/src/inputs/AutoCompleteInput/__stories__/Default.tsx +1 -1
- package/src/inputs/AutoCompleteInput/__stories__/Multiple.tsx +1 -1
- package/src/inputs/AutoCompleteInput/index.test.tsx +4 -0
- package/src/inputs/AutoCompleteInput/index.tsx +4 -6
- package/src/inputs/Checkboxes/Checkboxes.stories.js +3 -0
- package/src/inputs/Checkboxes/__stories__/Conditional.tsx +1 -1
- package/src/inputs/Checkboxes/__stories__/Default.tsx +1 -1
- package/src/inputs/Checkboxes/__stories__/WithDivider.tsx +1 -1
- package/src/inputs/Checkboxes/index.test.tsx +4 -0
- package/src/inputs/Checkboxes/index.tsx +95 -91
- package/src/inputs/DateInput/DateInput.stories.js +7 -0
- package/src/inputs/DateInput/__stories__/Default.tsx +1 -1
- package/src/inputs/DateInput/__stories__/WithDefaultValue.tsx +26 -0
- package/src/inputs/DateInput/__stories__/WithInitialValue.tsx +28 -0
- package/src/inputs/DateInput/__stories__/WithWrongDefaultValue.tsx +26 -0
- package/src/inputs/DateInput/__stories__/WithWrongInitialValue.tsx +28 -0
- package/src/inputs/DateInput/index.test.tsx +20 -0
- package/src/inputs/DateInput/index.tsx +65 -20
- package/src/inputs/DateTimeInput/DateTimeInput.stories.js +12 -6
- package/src/inputs/DateTimeInput/__stories__/Default.tsx +1 -1
- package/src/inputs/DateTimeInput/__stories__/WithDefaultValue.tsx +26 -0
- package/src/inputs/DateTimeInput/__stories__/WithInitialValue.tsx +28 -0
- package/src/inputs/DateTimeInput/__stories__/WithWrongDefaultValue.tsx +26 -0
- package/src/inputs/DateTimeInput/__stories__/WithWrongInitialValue.tsx +28 -0
- package/src/inputs/DateTimeInput/index.test.tsx +20 -0
- package/src/inputs/DateTimeInput/index.tsx +92 -40
- package/src/inputs/FileInput/FileInput.stories.js +4 -0
- package/src/inputs/FileInput/__stories__/Default.tsx +1 -1
- package/src/inputs/FileInput/__stories__/WithBorderAndLink.tsx +34 -0
- package/src/inputs/FileInput/index.test.tsx +8 -0
- package/src/inputs/FileInput/index.tsx +91 -47
- package/src/inputs/ImageInput/ImageInput.stories.js +5 -1
- package/src/inputs/ImageInput/__stories__/Default.tsx +1 -1
- package/src/inputs/ImageInput/__stories__/MaxSize.tsx +3 -2
- package/src/inputs/ImageInput/__stories__/{WithInvalidImageSize.tsx → WithInitialValues.tsx} +12 -3
- package/src/inputs/ImageInput/__stories__/WithInvalidImageDimension.tsx +1 -1
- package/src/inputs/ImageInput/__stories__/logo.d.ts +4 -0
- package/src/inputs/ImageInput/__stories__/logo.png +0 -0
- package/src/inputs/ImageInput/index.test.tsx +8 -4
- package/src/inputs/ImageInput/index.tsx +101 -49
- package/src/inputs/Input/Input.stories.js +5 -0
- package/src/inputs/Input/__stories__/AFM.tsx +1 -1
- package/src/inputs/Input/__stories__/AMKA.tsx +23 -0
- package/src/inputs/Input/__stories__/Boolean.tsx +1 -1
- package/src/inputs/Input/__stories__/Email.tsx +23 -0
- package/src/inputs/Input/__stories__/IBAN.tsx +1 -1
- package/src/inputs/Input/__stories__/Integer.tsx +1 -1
- package/src/inputs/Input/__stories__/LandlineNumber.tsx +1 -1
- package/src/inputs/Input/__stories__/MobilePhone.tsx +1 -1
- package/src/inputs/Input/__stories__/PhoneNumber.tsx +1 -1
- package/src/inputs/Input/__stories__/PostalCode.tsx +1 -1
- package/src/inputs/Input/__stories__/String.tsx +1 -1
- package/src/inputs/Input/__stories__/StringWithTrimValidation.tsx +1 -1
- package/src/inputs/Input/__stories__/TextWithLimit.tsx +1 -1
- package/src/inputs/Input/index.test.tsx +12 -0
- package/src/inputs/Input/index.tsx +76 -73
- package/src/inputs/Label/Label.stories.js +3 -0
- package/src/inputs/Label/__stories__/Default.tsx +1 -1
- package/src/inputs/Label/index.test.tsx +4 -0
- package/src/inputs/Label/index.tsx +1 -1
- package/src/inputs/OtpInput/OtpInput.stories.js +3 -0
- package/src/inputs/OtpInput/__stories__/Default.tsx +1 -1
- package/src/inputs/OtpInput/index.test.tsx +4 -0
- package/src/inputs/OtpInput/index.tsx +43 -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 +29 -21
- package/src/inputs/Select/Select.stories.js +3 -0
- package/src/inputs/Select/__stories__/Default.tsx +1 -1
- package/src/inputs/Select/index.test.tsx +4 -0
- package/src/inputs/Select/index.tsx +9 -6
- package/src/{Field/utils/index.ts → inputs/registry.ts} +5 -1
- package/src/lazy.js +12 -10
- package/src/registry.js +25 -15
- package/src/types.tsx +13 -5
- package/src/utils.ts +30 -8
- package/src/validators/index.ts +27 -15
- package/src/validators/types.ts +1 -1
- package/src/validators/utils/amka.ts +39 -0
- package/src/validators/utils/date.ts +30 -6
- package/src/validators/utils/datetime.ts +123 -31
- package/src/validators/utils/file.ts +35 -21
- package/src/validators/utils/iban.ts +2 -2
- package/src/validators/utils/image.ts +2 -2
- package/src/validators/utils/index.ts +6 -3
- package/src/validators/utils/int.ts +1 -1
- package/src/validators/utils/number.ts +1 -1
- package/src/validators/utils/otp.ts +2 -2
- package/src/validators/utils/phone.ts +2 -2
- package/src/validators/utils/postal_code.ts +2 -2
- package/src/validators/utils/text_limit.ts +2 -2
- package/types.d.ts +9 -4
- package/types.js.map +1 -1
- package/utils/index.js +20 -6
- package/utils.d.ts +3 -1
- package/utils.js.map +2 -2
- package/validators/index.d.ts +6 -6
- package/validators/index.js +12 -6
- package/validators/index.js.map +2 -2
- package/validators/types.d.ts +1 -1
- package/validators/utils/amka/index.js +36 -0
- package/{inputs/inputsScenarios → validators/utils/amka}/package.json +1 -1
- package/validators/utils/amka.d.ts +6 -0
- package/validators/utils/amka.js.map +7 -0
- package/validators/utils/date/index.js +26 -3
- package/validators/utils/date.d.ts +3 -3
- package/validators/utils/date.js.map +2 -2
- package/validators/utils/datetime/index.js +118 -24
- package/validators/utils/datetime.d.ts +3 -3
- package/validators/utils/datetime.js.map +2 -2
- package/validators/utils/file/index.js +30 -17
- package/validators/utils/file.d.ts +2 -2
- package/validators/utils/file.js.map +2 -2
- package/validators/utils/iban.d.ts +2 -2
- package/validators/utils/iban.js.map +1 -1
- package/validators/utils/image.d.ts +2 -2
- package/validators/utils/image.js.map +1 -1
- package/validators/utils/index.d.ts +3 -2
- package/validators/utils/index.js +4 -1
- package/validators/utils/index.js.map +2 -2
- package/validators/utils/int.d.ts +1 -1
- package/validators/utils/int.js.map +1 -1
- package/validators/utils/number.d.ts +1 -1
- package/validators/utils/number.js.map +1 -1
- package/validators/utils/otp.d.ts +2 -2
- package/validators/utils/otp.js.map +1 -1
- package/validators/utils/phone.d.ts +2 -2
- package/validators/utils/phone.js.map +1 -1
- package/validators/utils/postal_code.d.ts +2 -2
- package/validators/utils/postal_code.js.map +1 -1
- package/validators/utils/text_limit.d.ts +2 -2
- package/validators/utils/text_limit.js.map +1 -1
- package/Field/utils/calculateField/index.js +0 -27
- package/Field/utils/calculateField.d.ts +0 -2
- package/Field/utils/calculateField.js.map +0 -7
- package/Field/utils/index.js.map +0 -7
- package/FieldArray/FormDialog.d.ts +0 -53
- package/FieldArray/FormDialog.js.map +0 -7
- package/FormBuilder/index.test.d.ts +0 -1
- package/FormBuilder/interaction.test.d.ts +0 -1
- package/FormBuilder/scenarios.test.d.ts +0 -88
- package/MultiplicityField/index.test.d.ts +0 -1
- package/Questions/index.spec.d.ts +0 -1
- package/Questions/index.test.d.ts +0 -1
- package/cjs/Field/utils/calculateField/index.js +0 -50
- package/cjs/Field/utils/calculateField.js.map +0 -7
- package/cjs/Field/utils/index.js.map +0 -7
- package/cjs/FieldArray/FormDialog.js.map +0 -7
- package/cjs/inputs/Input/inputsInputScenarios/index.js +0 -439
- package/cjs/inputs/Input/inputsInputScenarios.js.map +0 -7
- package/cjs/inputs/inputsScenarios/index.js +0 -533
- package/cjs/inputs/inputsScenarios.js.map +0 -7
- package/cjs/locales/el.js.map +0 -7
- package/inputs/AutoCompleteInput/index.test.d.ts +0 -1
- package/inputs/Checkboxes/index.test.d.ts +0 -1
- package/inputs/DateInput/index.test.d.ts +0 -1
- package/inputs/DateTimeInput/index.test.d.ts +0 -1
- package/inputs/FileInput/index.test.d.ts +0 -1
- package/inputs/ImageInput/__stories__/WithInvalidImageSize.d.ts +0 -3
- package/inputs/ImageInput/index.test.d.ts +0 -1
- package/inputs/Input/index.test.d.ts +0 -1
- package/inputs/Input/inputsInputScenarios/index.js +0 -406
- package/inputs/Input/inputsInputScenarios.d.ts +0 -57
- package/inputs/Input/inputsInputScenarios.js.map +0 -7
- package/inputs/Label/index.test.d.ts +0 -1
- package/inputs/OtpInput/index.test.d.ts +0 -1
- package/inputs/Radio/index.test.d.ts +0 -1
- package/inputs/Select/index.test.d.ts +0 -1
- package/inputs/inputsScenarios/index.js +0 -499
- package/inputs/inputsScenarios.d.ts +0 -296
- package/inputs/inputsScenarios.js.map +0 -7
- package/locales/el/index.js +0 -6
- package/locales/el.d.ts +0 -2
- package/locales/el.js.map +0 -7
- package/src/Field/utils/calculateField.ts +0 -49
- package/src/FieldArray/FormDialog.tsx +0 -378
- package/src/inputs/Input/inputsInputScenarios.ts +0 -404
- package/src/inputs/inputsScenarios.ts +0 -496
- package/src/locales/el.ts +0 -3
- /package/{FieldArray/index.test.d.ts → hooks/__tests__/utils.spec.d.ts} +0 -0
package/src/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,
|
|
@@ -30,13 +32,15 @@ import {
|
|
|
30
32
|
import { INT_VALIDATOR } from '@digigov/form/validators/utils/int';
|
|
31
33
|
import { NUMBER_VALIDATOR } from '@digigov/form/validators/utils/number';
|
|
32
34
|
|
|
33
|
-
export const getYUPTypeMap = (
|
|
35
|
+
export const getYUPTypeMap = (
|
|
36
|
+
validatorRegistry?: Record<string, any>
|
|
37
|
+
): Record<string, any> => {
|
|
34
38
|
const yupTypeMap = {
|
|
35
39
|
file: (field): MixedSchema => {
|
|
36
40
|
return yup
|
|
37
41
|
.mixed()
|
|
38
42
|
.transform((value) => {
|
|
39
|
-
if (!value.length) {
|
|
43
|
+
if (!value || value.length === 0) {
|
|
40
44
|
return null;
|
|
41
45
|
}
|
|
42
46
|
return value;
|
|
@@ -81,10 +85,13 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
81
85
|
if (typeof field.extra.of === 'object') {
|
|
82
86
|
// else if the field is an object then it is a scalar type
|
|
83
87
|
// eg. number, string etc.
|
|
88
|
+
if (field.required) {
|
|
89
|
+
field.extra.min = 1;
|
|
90
|
+
}
|
|
84
91
|
let arrayValidator = yup
|
|
85
92
|
.array()
|
|
86
|
-
.
|
|
87
|
-
.
|
|
93
|
+
.nullable()
|
|
94
|
+
.of(yupTypeMap[field.extra.of.type](field.extra.of));
|
|
88
95
|
if (field.extra.length)
|
|
89
96
|
arrayValidator = arrayValidator.length(field.extra.length, {
|
|
90
97
|
key: 'form.error.array.length',
|
|
@@ -133,6 +140,10 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
133
140
|
field.trim
|
|
134
141
|
? yup.string().trim().test(AFM_VALIDATOR)
|
|
135
142
|
: yup.string().test(AFM_VALIDATOR),
|
|
143
|
+
amka: (field): yup.StringSchema =>
|
|
144
|
+
field.trim
|
|
145
|
+
? yup.string().trim().test(AMKA_VALIDATOR)
|
|
146
|
+
: yup.string().test(AMKA_VALIDATOR),
|
|
136
147
|
uuid4: (field): yup.StringSchema =>
|
|
137
148
|
field.trim
|
|
138
149
|
? yup.string().trim().test(UUID4_VALIDATOR)
|
|
@@ -215,6 +226,7 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
215
226
|
}
|
|
216
227
|
return yup.string().test(DATETIME_VALIDATOR);
|
|
217
228
|
},
|
|
229
|
+
...validatorRegistry,
|
|
218
230
|
};
|
|
219
231
|
return yupTypeMap;
|
|
220
232
|
};
|
|
@@ -226,7 +238,7 @@ export function useValidationSchema(
|
|
|
226
238
|
validatorRegistry?: Record<string, ValidatorSchema[]>
|
|
227
239
|
): Lazy<any, unknown> | AnyObjectSchema | void {
|
|
228
240
|
return useMemo(() => {
|
|
229
|
-
const yupTypeMap = getYUPTypeMap();
|
|
241
|
+
const yupTypeMap = getYUPTypeMap(validatorRegistry);
|
|
230
242
|
return getYupObjectShape(fields, yupTypeMap, validatorRegistry);
|
|
231
|
-
}, []);
|
|
243
|
+
}, [fields, validatorRegistry]);
|
|
232
244
|
}
|
package/src/validators/types.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import * as yup from 'yup';
|
|
1
|
+
import type * as yup from 'yup';
|
|
2
2
|
export type ValidatorSchema = yup.TestConfig;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
function digitSum(number) {
|
|
2
|
+
const sum = number > 9 ? 1 : 0;
|
|
3
|
+
return sum + (number % 10);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function validateAMKA(amka: string): boolean {
|
|
7
|
+
// Validate that the last digit is the correct check digit (created using the
|
|
8
|
+
// Luhn algorithm https://en.wikipedia.org/wiki/Luhn_algorithm).
|
|
9
|
+
amka = String(amka);
|
|
10
|
+
const checkDigitIndex = amka.length - 1;
|
|
11
|
+
let sum = 0;
|
|
12
|
+
amka
|
|
13
|
+
.substring(0, checkDigitIndex)
|
|
14
|
+
.split('')
|
|
15
|
+
.reverse()
|
|
16
|
+
.forEach(function (value, index) {
|
|
17
|
+
const weight = ((index + 1) % 2) + 1;
|
|
18
|
+
sum += digitSum(parseInt(value, 10) * weight);
|
|
19
|
+
});
|
|
20
|
+
const sumMod10 = sum % 10;
|
|
21
|
+
if (sumMod10 === 0) {
|
|
22
|
+
return amka.substring(checkDigitIndex) === '0';
|
|
23
|
+
} else {
|
|
24
|
+
return amka.substring(checkDigitIndex) === 10 - sumMod10 + '';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const AMKA_VALIDATOR = {
|
|
29
|
+
name: 'amka-validator',
|
|
30
|
+
message: 'form.error.amka',
|
|
31
|
+
test: (value): boolean => {
|
|
32
|
+
if (!value) return true;
|
|
33
|
+
const AMKA_REGEX = /^[0-9]{11}$/;
|
|
34
|
+
if (!AMKA_REGEX.test(value) || value === '00000000000') {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
return validateAMKA(value);
|
|
38
|
+
},
|
|
39
|
+
};
|
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import dayjs from 'dayjs';
|
|
2
2
|
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
3
|
-
import { FieldSpec } from '@digigov/form/types';
|
|
4
|
-
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
3
|
+
import type { FieldSpec } from '@digigov/form/types';
|
|
4
|
+
import type { ValidatorSchema } from '@digigov/form/validators/types';
|
|
5
5
|
|
|
6
6
|
dayjs.extend(customParseFormat);
|
|
7
7
|
|
|
8
8
|
const VALID_DATE_FORMATS = ['DD/MM/YYYY'];
|
|
9
9
|
const DATE_CACHE = {};
|
|
10
|
+
const onlyNumbersRegex = /^\d+$/;
|
|
10
11
|
|
|
11
12
|
const getDate = (v: string) => {
|
|
12
13
|
return DATE_CACHE[v] ? DATE_CACHE[v] : dayjs(v, VALID_DATE_FORMATS, true);
|
|
13
14
|
};
|
|
14
15
|
|
|
16
|
+
const getDaysInMonth = (month: number, year: number): number => {
|
|
17
|
+
return dayjs(`${year}-${month}-01`).daysInMonth(); // e.g. 29 for Feb 2024
|
|
18
|
+
};
|
|
19
|
+
|
|
15
20
|
// Function to check partial date completion
|
|
16
21
|
const checkPartialDate = (value: string) => {
|
|
17
|
-
console.log("value.split('/')", value.split('/'));
|
|
18
22
|
const [day, month, year] = value.split('/');
|
|
19
23
|
if (day && !month && !year) {
|
|
20
24
|
return 'form.error.date.invalid_month_year';
|
|
@@ -33,9 +37,29 @@ const checkPartialDate = (value: string) => {
|
|
|
33
37
|
}
|
|
34
38
|
if (!day && month && year) {
|
|
35
39
|
return 'form.error.date.invalid_day';
|
|
36
|
-
} else {
|
|
37
|
-
return 'form.error.date.invalid';
|
|
38
40
|
}
|
|
41
|
+
if (day && month) {
|
|
42
|
+
const dayNum = parseInt(day);
|
|
43
|
+
const monthNum = parseInt(month);
|
|
44
|
+
const validYear = onlyNumbersRegex.test(year) ? year : undefined;
|
|
45
|
+
if (!validYear || year.length < 4) {
|
|
46
|
+
return 'form.error.date.invalid';
|
|
47
|
+
}
|
|
48
|
+
const yearNum = parseInt(validYear);
|
|
49
|
+
const maxDay = getDaysInMonth(monthNum, yearNum);
|
|
50
|
+
if (dayNum < 1 || dayNum > maxDay) {
|
|
51
|
+
return {
|
|
52
|
+
key: 'form.error.date.invalid_day_range',
|
|
53
|
+
context: {
|
|
54
|
+
maxDay: maxDay,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
if (monthNum < 1 || monthNum > 12) {
|
|
59
|
+
return 'form.error.datetime.invalid_month_range';
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return 'form.error.date.invalid';
|
|
39
63
|
};
|
|
40
64
|
|
|
41
65
|
export const LATER_THAN_VALIDATOR = (field: FieldSpec): ValidatorSchema => {
|
|
@@ -96,7 +120,7 @@ export const EARLIER_THAN_VALIDATOR = (field: FieldSpec): ValidatorSchema => {
|
|
|
96
120
|
|
|
97
121
|
export const DATE_VALIDATOR = {
|
|
98
122
|
name: 'date-validator',
|
|
99
|
-
message: (v): string => {
|
|
123
|
+
message: (v): string | object => {
|
|
100
124
|
return checkPartialDate(v.value);
|
|
101
125
|
},
|
|
102
126
|
test: function (value: string) {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import dayjs from 'dayjs';
|
|
2
2
|
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
3
|
-
import { FieldSpec } from '@digigov/form/types';
|
|
4
|
-
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
3
|
+
import type { FieldSpec } from '@digigov/form/types';
|
|
4
|
+
import type { ValidatorSchema } from '@digigov/form/validators/types';
|
|
5
5
|
|
|
6
6
|
dayjs.extend(customParseFormat);
|
|
7
7
|
|
|
8
8
|
const VALID_DATETIME_FORMATS = ['DD/MM/YYYY HH:mm'];
|
|
9
9
|
const DATETIME_CACHE = {};
|
|
10
|
+
const onlyNumbersRegex = /^\d+$/;
|
|
10
11
|
|
|
11
12
|
const getDateTime = (v: string) => {
|
|
12
13
|
return DATETIME_CACHE[v]
|
|
@@ -14,54 +15,145 @@ const getDateTime = (v: string) => {
|
|
|
14
15
|
: dayjs(v, VALID_DATETIME_FORMATS, true);
|
|
15
16
|
};
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
const getDaysInMonth = (month: number, year: number): number => {
|
|
19
|
+
return dayjs(`${year}-${month}-01`).daysInMonth(); // e.g. 29 for Feb 2024
|
|
20
|
+
};
|
|
21
|
+
|
|
18
22
|
const checkPartialDateTime = (value: string) => {
|
|
19
23
|
const [datePart, timePart] = value.split(' ');
|
|
20
|
-
const [day, month, year] = datePart
|
|
21
|
-
const [hours, minutes] = timePart
|
|
24
|
+
const [day, month, year] = datePart?.split('/') ?? [];
|
|
25
|
+
const [hours, minutes] = timePart?.split(':') ?? [];
|
|
26
|
+
|
|
27
|
+
const hasDay = Boolean(day);
|
|
28
|
+
const hasMonth = Boolean(month);
|
|
29
|
+
const hasYear = Boolean(year);
|
|
30
|
+
const hasHours = Boolean(hours);
|
|
31
|
+
const hasMinutes = Boolean(minutes);
|
|
22
32
|
|
|
23
|
-
|
|
24
|
-
|
|
33
|
+
if (hasDay && !hasMonth && !hasYear && !hasHours && !hasMinutes) {
|
|
34
|
+
return 'form.error.datetime.invalid_month_year_hours_minutes';
|
|
35
|
+
}
|
|
36
|
+
if (!hasDay && hasMonth && !hasYear && !hasHours && !hasMinutes) {
|
|
37
|
+
return 'form.error.datetime.invalid_day_year_hours_minutes';
|
|
38
|
+
}
|
|
39
|
+
if (!hasDay && !hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
40
|
+
return 'form.error.datetime.invalid_day_month_hours_minutes';
|
|
41
|
+
}
|
|
42
|
+
if (hasDay && hasMonth && !hasYear && !hasHours && !hasMinutes) {
|
|
43
|
+
return 'form.error.datetime.invalid_year_hours_minutes';
|
|
44
|
+
}
|
|
45
|
+
if (hasDay && !hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
46
|
+
return 'form.error.datetime.invalid_month_hours_minutes';
|
|
47
|
+
}
|
|
48
|
+
if (!hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
49
|
+
return 'form.error.datetime.invalid_day_hours_minutes';
|
|
50
|
+
}
|
|
51
|
+
if (hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
52
|
+
return 'form.error.datetime.invalid__hours_minutes';
|
|
53
|
+
}
|
|
54
|
+
if (hasDay && hasMonth && hasYear && hasHours && !hasMinutes) {
|
|
55
|
+
return 'form.error.datetime.invalid_minutes';
|
|
56
|
+
}
|
|
57
|
+
if (hasDay && hasMonth && hasYear && !hasHours && hasMinutes) {
|
|
58
|
+
return 'form.error.datetime.invalid_hours';
|
|
59
|
+
}
|
|
60
|
+
if (hasDay && !hasMonth && !hasYear && hasHours && !hasMinutes) {
|
|
61
|
+
return 'form.error.datetime.invalid_month_year_minutes';
|
|
62
|
+
}
|
|
63
|
+
if (hasDay && !hasMonth && !hasYear && !hasHours && hasMinutes) {
|
|
64
|
+
return 'form.error.datetime.invalid_month_year_hours';
|
|
65
|
+
}
|
|
66
|
+
if (hasDay && !hasMonth && !hasYear && hasHours && hasMinutes) {
|
|
25
67
|
return 'form.error.datetime.invalid_month_year';
|
|
26
68
|
}
|
|
27
|
-
if (!
|
|
69
|
+
if (!hasDay && hasMonth && !hasYear && hasHours && !hasMinutes) {
|
|
70
|
+
return 'form.error.datetime.invalid_day_year_minutes';
|
|
71
|
+
}
|
|
72
|
+
if (!hasDay && hasMonth && !hasYear && !hasHours && hasMinutes) {
|
|
73
|
+
return 'form.error.datetime.invalid_day_year_hours';
|
|
74
|
+
}
|
|
75
|
+
if (!hasDay && hasMonth && !hasYear && hasHours && hasMinutes) {
|
|
28
76
|
return 'form.error.datetime.invalid_day_year';
|
|
29
77
|
}
|
|
30
|
-
if (!
|
|
78
|
+
if (!hasDay && !hasMonth && hasYear && hasHours && !hasMinutes) {
|
|
79
|
+
return 'form.error.datetime.invalid_day_month_minutes';
|
|
80
|
+
}
|
|
81
|
+
if (!hasDay && !hasMonth && hasYear && !hasHours && hasMinutes) {
|
|
82
|
+
return 'form.error.datetime.invalid_day_month_hours';
|
|
83
|
+
}
|
|
84
|
+
if (!hasDay && !hasMonth && hasYear && hasHours && hasMinutes) {
|
|
31
85
|
return 'form.error.datetime.invalid_day_month';
|
|
32
86
|
}
|
|
33
|
-
if (
|
|
87
|
+
if (!hasDay && !hasMonth && !hasYear && hasHours && hasMinutes) {
|
|
88
|
+
return 'form.error.datetime.invalid_day_month_year';
|
|
89
|
+
}
|
|
90
|
+
if (!hasDay && !hasMonth && !hasYear && !hasHours && hasMinutes) {
|
|
91
|
+
return 'form.error.datetime.invalid_day_month_year_hours';
|
|
92
|
+
}
|
|
93
|
+
if (hasDay && hasMonth && !hasYear && hasHours && !hasMinutes) {
|
|
94
|
+
return 'form.error.datetime.invalid_year_minutes';
|
|
95
|
+
}
|
|
96
|
+
if (hasDay && hasMonth && !hasYear && !hasHours && hasMinutes) {
|
|
97
|
+
return 'form.error.datetime.invalid_year_hours';
|
|
98
|
+
}
|
|
99
|
+
if (hasDay && hasMonth && !hasYear && hasHours && hasMinutes) {
|
|
34
100
|
return 'form.error.datetime.invalid_year';
|
|
35
101
|
}
|
|
36
|
-
if (
|
|
102
|
+
if (hasDay && !hasMonth && hasYear && hasHours && !hasMinutes) {
|
|
103
|
+
return 'form.error.datetime.invalid_month_minutes';
|
|
104
|
+
}
|
|
105
|
+
if (hasDay && !hasMonth && hasYear && !hasHours && hasMinutes) {
|
|
106
|
+
return 'form.error.datetime.invalid_month_hours';
|
|
107
|
+
}
|
|
108
|
+
if (hasDay && !hasMonth && hasYear && hasHours && hasMinutes) {
|
|
37
109
|
return 'form.error.datetime.invalid_month';
|
|
38
110
|
}
|
|
39
|
-
if (!
|
|
111
|
+
if (!hasDay && hasMonth && hasYear && hasHours && !hasMinutes) {
|
|
112
|
+
return 'form.error.datetime.invalid_day_minutes';
|
|
113
|
+
}
|
|
114
|
+
if (!hasDay && hasMonth && hasYear && !hasHours && hasMinutes) {
|
|
115
|
+
return 'form.error.datetime.invalid_day_hours';
|
|
116
|
+
}
|
|
117
|
+
if (!hasDay && hasMonth && hasYear && hasHours && hasMinutes) {
|
|
40
118
|
return 'form.error.datetime.invalid_day';
|
|
41
119
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
120
|
+
if (!hasDay && !hasMonth && !hasYear && hasHours && !hasMinutes) {
|
|
121
|
+
return 'form.error.datetime.invalid_day_month_year_minutes';
|
|
122
|
+
}
|
|
123
|
+
if (hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
124
|
+
return 'form.error.datetime.invalid_hours_minutes';
|
|
125
|
+
}
|
|
126
|
+
if (day && month) {
|
|
127
|
+
const dayNum = parseInt(day);
|
|
128
|
+
const monthNum = parseInt(month);
|
|
129
|
+
const validYear = onlyNumbersRegex.test(year) ? year : undefined;
|
|
130
|
+
if (!validYear || year.length < 4) {
|
|
131
|
+
return 'form.error.datetime.invalid';
|
|
46
132
|
}
|
|
47
|
-
|
|
48
|
-
|
|
133
|
+
const yearNum = parseInt(validYear);
|
|
134
|
+
const maxDay = getDaysInMonth(monthNum, yearNum);
|
|
135
|
+
if (dayNum < 1 || dayNum > maxDay) {
|
|
136
|
+
return {
|
|
137
|
+
key: 'form.error.datetime.invalid_day_range',
|
|
138
|
+
context: {
|
|
139
|
+
maxDay: maxDay,
|
|
140
|
+
},
|
|
141
|
+
};
|
|
49
142
|
}
|
|
50
|
-
if (
|
|
51
|
-
return 'form.error.datetime.
|
|
143
|
+
if (monthNum < 1 || monthNum > 12) {
|
|
144
|
+
return 'form.error.datetime.invalid_month_range';
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (hours && minutes) {
|
|
148
|
+
const hoursNum = parseInt(hours);
|
|
149
|
+
const minutesNum = parseInt(minutes);
|
|
150
|
+
if (hoursNum < 0 || hoursNum > 23) {
|
|
151
|
+
return 'form.error.datetime.invalid_hours_range';
|
|
52
152
|
}
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
const minutesNum = parseInt(minutes);
|
|
56
|
-
if (hoursNum < 0 || hoursNum > 23) {
|
|
57
|
-
return 'form.error.datetime.invalid_hours_range';
|
|
58
|
-
}
|
|
59
|
-
if (minutesNum < 0 || minutesNum > 59) {
|
|
60
|
-
return 'form.error.datetime.invalid_minutes_range';
|
|
61
|
-
}
|
|
153
|
+
if (minutesNum < 0 || minutesNum > 59) {
|
|
154
|
+
return 'form.error.datetime.invalid_minutes_range';
|
|
62
155
|
}
|
|
63
156
|
}
|
|
64
|
-
|
|
65
157
|
return 'form.error.datetime.invalid';
|
|
66
158
|
};
|
|
67
159
|
|
|
@@ -119,7 +211,7 @@ export const EARLIER_THAN_DATETIME_VALIDATOR = (
|
|
|
119
211
|
|
|
120
212
|
export const DATETIME_VALIDATOR = {
|
|
121
213
|
name: 'datetime-validator',
|
|
122
|
-
message: (v): string => {
|
|
214
|
+
message: (v): string | object => {
|
|
123
215
|
return checkPartialDateTime(v.value);
|
|
124
216
|
},
|
|
125
217
|
test: function (value: string) {
|
|
@@ -1,27 +1,41 @@
|
|
|
1
|
-
import { FieldSpec } from '@digigov/form/types';
|
|
2
|
-
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
1
|
+
import type { FieldSpec } from '@digigov/form/types';
|
|
2
|
+
import type { ValidatorSchema } from '@digigov/form/validators/types';
|
|
3
3
|
|
|
4
4
|
const DEFAULT_FILE_MAX_SIZE = 10000000;
|
|
5
5
|
|
|
6
|
-
export const FILE_MAX_SIZE_VALIDATOR = (field: FieldSpec): ValidatorSchema =>
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
export const FILE_MAX_SIZE_VALIDATOR = (field: FieldSpec): ValidatorSchema => {
|
|
7
|
+
const maxSizeInBytes = field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE;
|
|
8
|
+
let maxSizeTransformed = maxSizeInBytes / (1024 * 1024); // In MB
|
|
9
|
+
let maxSizeText = 'MB';
|
|
10
|
+
if (Math.round(maxSizeTransformed) === 0) {
|
|
11
|
+
maxSizeTransformed = Math.round(maxSizeInBytes / 1024);
|
|
12
|
+
maxSizeText = 'KB';
|
|
13
|
+
}
|
|
14
|
+
if (Math.round(maxSizeTransformed) === 0) {
|
|
15
|
+
maxSizeTransformed = maxSizeInBytes;
|
|
16
|
+
maxSizeText = 'Bytes';
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
name: 'file-max-size-validator',
|
|
20
|
+
message: {
|
|
21
|
+
key:
|
|
22
|
+
field.type === 'file'
|
|
23
|
+
? 'form.error.file_size'
|
|
24
|
+
: 'form.error.image_size',
|
|
25
|
+
context: {
|
|
26
|
+
maxSize: `${maxSizeTransformed} ${maxSizeText}`,
|
|
27
|
+
},
|
|
14
28
|
},
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
29
|
+
test: (value: File[]): boolean => {
|
|
30
|
+
if (value) {
|
|
31
|
+
for (const file of Array.from(value)) {
|
|
32
|
+
const maxSize = field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE;
|
|
33
|
+
if (file.size > maxSize) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
22
36
|
}
|
|
23
37
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
}
|
|
38
|
+
return true;
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FieldSpec } from '@digigov/form/types';
|
|
2
|
-
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
1
|
+
import type { FieldSpec } from '@digigov/form/types';
|
|
2
|
+
import type { ValidatorSchema } from '@digigov/form/validators/types';
|
|
3
3
|
export function validateIban(value: string, countryCode: string): boolean {
|
|
4
4
|
value = value.replace(/\s/g, '').replace(/-/g, '');
|
|
5
5
|
if (value.match(/^[0-9]*$/i)) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FieldSpec } from '@digigov/form/types';
|
|
2
|
-
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
1
|
+
import type { FieldSpec } from '@digigov/form/types';
|
|
2
|
+
import type { ValidatorSchema } from '@digigov/form/validators/types';
|
|
3
3
|
|
|
4
4
|
const DEFAULT_IMAGE_MAX_HEIGHT_SIZE = 2000;
|
|
5
5
|
const DEFAULT_IMAGE_MAX_WIDTH_SIZE = 2000;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as yup from 'yup';
|
|
2
|
-
import { FieldSpec } from '@digigov/form/types';
|
|
3
|
-
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
2
|
+
import type { FieldSpec } from '@digigov/form/types';
|
|
3
|
+
import type { ValidatorSchema } from '@digigov/form/validators/types';
|
|
4
4
|
|
|
5
5
|
export * from '@digigov/form/validators/utils/afm';
|
|
6
|
+
export * from '@digigov/form/validators/utils/amka';
|
|
6
7
|
export * from '@digigov/form/validators/utils/file';
|
|
7
8
|
export * from '@digigov/form/validators/utils/iban';
|
|
8
9
|
export * from '@digigov/form/validators/utils/otp';
|
|
@@ -98,7 +99,9 @@ export function getYupObjectShape(
|
|
|
98
99
|
|
|
99
100
|
return yup.lazy(function () {
|
|
100
101
|
const fieldSchemas = computeShape(
|
|
101
|
-
Object.values(fields.current)
|
|
102
|
+
Object.values(fields.current).filter(
|
|
103
|
+
(f: FieldSpec) => !f.key.includes('.')
|
|
104
|
+
) as FieldSpec[],
|
|
102
105
|
yupTypeMap,
|
|
103
106
|
validatorRegistry
|
|
104
107
|
);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FieldSpec } from '@digigov/form/types';
|
|
2
|
-
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
1
|
+
import type { FieldSpec } from '@digigov/form/types';
|
|
2
|
+
import type { ValidatorSchema } from '@digigov/form/validators/types';
|
|
3
3
|
export function validateOtp(value: string, maxLength: number): boolean {
|
|
4
4
|
if (value.length === maxLength) {
|
|
5
5
|
return true;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FieldSpec } from '@digigov/form/types';
|
|
2
|
-
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
1
|
+
import type { FieldSpec } from '@digigov/form/types';
|
|
2
|
+
import type { ValidatorSchema } from '@digigov/form/validators/types';
|
|
3
3
|
|
|
4
4
|
export type PhoneNumberType = 'landline' | 'mobile' | null;
|
|
5
5
|
// add more countries from here libphonenumber-js/metadata.full.json
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FieldSpec } from '@digigov/form/types';
|
|
2
|
-
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
1
|
+
import type { FieldSpec } from '@digigov/form/types';
|
|
2
|
+
import type { ValidatorSchema } from '@digigov/form/validators/types';
|
|
3
3
|
|
|
4
4
|
const CODE_REGEX = /^[12345678][0-9]{4}$/;
|
|
5
5
|
export function validatePostalCode(
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FieldSpec } from '@digigov/form/types';
|
|
2
|
-
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
1
|
+
import type { FieldSpec } from '@digigov/form/types';
|
|
2
|
+
import type { ValidatorSchema } from '@digigov/form/validators/types';
|
|
3
3
|
|
|
4
4
|
export function validateText(value: string, min: number, max: number): boolean {
|
|
5
5
|
let validator;
|
package/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { UseFormReturn, UseFormProps } from 'react-hook-form';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { UseFormReturn, UseFormProps, ErrorOption } from 'react-hook-form';
|
|
2
|
+
import type { FieldLabelProps, FieldSpec, FormData } from '@digigov/form/Field/types';
|
|
3
|
+
import type { FieldComponentRegistry } from '@digigov/form/inputs/registry';
|
|
4
|
+
import type { ValidatorSchema } from '@digigov/form/validators/types';
|
|
4
5
|
export * from '@digigov/form/Field/types';
|
|
5
6
|
export interface FieldError {
|
|
6
7
|
message: string;
|
|
@@ -11,6 +12,7 @@ export interface FieldsetSpec {
|
|
|
11
12
|
label?: FieldLabelProps;
|
|
12
13
|
body?: React.ReactNode;
|
|
13
14
|
}
|
|
15
|
+
export type registerFieldFocus = (fieldName: string, element: HTMLElement) => (name: string) => void;
|
|
14
16
|
export interface FormContextProps {
|
|
15
17
|
fieldsetsMap?: Record<string, FieldsetSpec>;
|
|
16
18
|
fieldsMap: Record<string, FieldSpec>;
|
|
@@ -22,14 +24,16 @@ export interface FormContextProps {
|
|
|
22
24
|
getFieldState: UseFormReturn['getFieldState'];
|
|
23
25
|
setValue: UseFormReturn['setValue'];
|
|
24
26
|
getValues: UseFormReturn['getValues'];
|
|
27
|
+
getValuesFromParentForm?: UseFormReturn['getValues'];
|
|
25
28
|
unregister: UseFormReturn['unregister'];
|
|
26
29
|
formState: UseFormReturn['formState'];
|
|
27
30
|
reset: UseFormReturn['reset'];
|
|
28
31
|
resetField: UseFormReturn['resetField'];
|
|
29
32
|
registerField: (field: FieldSpec) => void;
|
|
33
|
+
registerFieldFocus: registerFieldFocus;
|
|
30
34
|
errors: UseFormReturn['formState']['errors'];
|
|
31
35
|
componentRegistry?: FieldComponentRegistry;
|
|
32
|
-
submit: () => Promise<void
|
|
36
|
+
submit: () => Promise<void> | void;
|
|
33
37
|
}
|
|
34
38
|
export interface FormBuilderProps {
|
|
35
39
|
fields?: FieldSpec[];
|
|
@@ -46,6 +50,7 @@ export interface FormBuilderProps {
|
|
|
46
50
|
componentRegistry?: FieldComponentRegistry;
|
|
47
51
|
grid?: boolean;
|
|
48
52
|
controlledFieldsOnly?: boolean;
|
|
53
|
+
errors?: ErrorOption;
|
|
49
54
|
}
|
|
50
55
|
export interface FormBaseProps extends Omit<FormBuilderProps, 'fields' | 'fieldsets' | 'auto'> {
|
|
51
56
|
fieldsetsMap?: Record<string, FieldsetSpec>;
|
package/types.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/types.tsx"],
|
|
4
|
-
"sourcesContent": ["import { UseFormReturn, UseFormProps } from 'react-hook-form';\nimport {\n
|
|
4
|
+
"sourcesContent": ["import type { UseFormReturn, UseFormProps, ErrorOption } from 'react-hook-form';\nimport type {\n FieldLabelProps,\n FieldSpec,\n FormData,\n} from '@digigov/form/Field/types';\nimport type { FieldComponentRegistry } from '@digigov/form/inputs/registry';\nimport type { ValidatorSchema } from '@digigov/form/validators/types';\nexport * from '@digigov/form/Field/types';\nexport interface FieldError {\n message: string;\n}\n\nexport interface FieldsetSpec {\n key: string;\n fields: string[];\n label?: FieldLabelProps;\n body?: React.ReactNode;\n}\n\nexport type registerFieldFocus = (\n fieldName: string,\n element: HTMLElement\n) => (name: string) => void;\n\nexport interface FormContextProps {\n fieldsetsMap?: Record<string, FieldsetSpec>;\n fieldsMap: Record<string, FieldSpec>;\n control: UseFormReturn['control'];\n register: UseFormReturn['register'];\n trigger: UseFormReturn['trigger'];\n clearErrors: UseFormReturn['clearErrors'];\n watch: UseFormReturn['watch'];\n getFieldState: UseFormReturn['getFieldState'];\n setValue: UseFormReturn['setValue'];\n getValues: UseFormReturn['getValues'];\n getValuesFromParentForm?: UseFormReturn['getValues'];\n unregister: UseFormReturn['unregister'];\n formState: UseFormReturn['formState'];\n reset: UseFormReturn['reset'];\n resetField: UseFormReturn['resetField'];\n registerField: (field: FieldSpec) => void;\n registerFieldFocus: registerFieldFocus;\n errors: UseFormReturn['formState']['errors'];\n componentRegistry?: FieldComponentRegistry;\n submit: () => Promise<void> | void;\n}\n\nexport interface FormBuilderProps {\n fields?: FieldSpec[];\n fieldsets?: FieldsetSpec[];\n initial?: FormData;\n onSubmit?: (data: FormData) => void | null | FieldError[];\n mode?: UseFormProps['mode'];\n reValidateMode?: UseFormProps['reValidateMode'];\n criteriaMode?: UseFormProps['criteriaMode'];\n children?: React.ReactNode;\n shouldFocusError?: boolean;\n auto?: boolean;\n validatorRegistry?: Record<string, ValidatorSchema[]>;\n componentRegistry?: FieldComponentRegistry;\n grid?: boolean;\n controlledFieldsOnly?: boolean;\n errors?: ErrorOption;\n}\n\nexport interface FormBaseProps\n extends Omit<FormBuilderProps, 'fields' | 'fieldsets' | 'auto'> {\n fieldsetsMap?: Record<string, FieldsetSpec>;\n fieldsMap: Record<string, FieldSpec>;\n registerField: (field: FieldSpec) => void;\n resolver: any;\n}\n"],
|
|
5
5
|
"mappings": "AAQA,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|