@digigov/form 2.0.0-a32ad9b2 → 2.0.0-abd768eb
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/FieldBase/index.js +7 -2
- package/Field/FieldBase.js.map +2 -2
- package/Field/FieldBaseContainer/index.js +37 -18
- package/Field/FieldBaseContainer.d.ts +1 -1
- package/Field/FieldBaseContainer.js.map +2 -2
- package/Field/FieldConditional/index.js +4 -0
- package/Field/FieldConditional.js.map +2 -2
- package/Field/index.js +10 -4
- package/Field/index.js.map +2 -2
- package/Field/types.d.ts +10 -3
- package/Field/utils/index.js +3 -1
- package/Field/utils/index.js.map +2 -2
- package/Field/utils/useField/index.js +8 -1
- package/Field/utils/useField.js.map +2 -2
- package/FieldArray/FormDialog/index.js +314 -196
- package/FieldArray/FormDialog.d.ts +20 -7
- package/FieldArray/FormDialog.js.map +3 -3
- 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 +1 -0
- package/FieldArray/index.js +32 -8
- package/FieldArray/index.js.map +2 -2
- package/FieldObject/index.d.ts +3 -0
- package/FieldObject/index.js +26 -15
- package/FieldObject/index.js.map +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 +1 -1
- package/FormBuilder/index.js +11 -7
- package/FormBuilder/index.js.map +2 -2
- package/FormContext/index.js +6 -2
- package/FormContext.d.ts +1 -0
- package/FormContext.js.map +2 -2
- package/MultiplicityField/MultiplicityField.stories.d.ts +2 -0
- package/MultiplicityField/__stories__/Default.d.ts +1 -1
- package/MultiplicityField/__stories__/PreviewDisplay.d.ts +1 -1
- package/MultiplicityField/__stories__/WithExactLength.d.ts +1 -1
- package/MultiplicityField/__stories__/WithMaxLength.d.ts +1 -1
- package/MultiplicityField/__stories__/WithMinAndMaxLength.d.ts +1 -1
- package/MultiplicityField/__stories__/WithMinLength.d.ts +1 -1
- package/MultiplicityField/add-objects/index.js +2 -0
- package/MultiplicityField/add-objects.js.map +2 -2
- package/MultiplicityField/index.js +4 -1
- package/MultiplicityField/index.js.map +2 -2
- package/MultiplicityField/types.d.ts +1 -0
- package/Questions/Questions.stories.d.ts +2 -0
- package/Questions/__stories__/Default.d.ts +1 -1
- package/cjs/Field/FieldBase/index.js +7 -2
- 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 +10 -4
- package/cjs/Field/index.js.map +2 -2
- package/cjs/Field/types.js.map +1 -1
- package/cjs/Field/utils/index.js +3 -1
- package/cjs/Field/utils/index.js.map +2 -2
- package/cjs/Field/utils/useField/index.js +8 -1
- package/cjs/Field/utils/useField.js.map +2 -2
- package/cjs/FieldArray/FormDialog/index.js +309 -194
- package/cjs/FieldArray/FormDialog.js.map +3 -3
- package/cjs/FieldArray/index.js +31 -7
- package/cjs/FieldArray/index.js.map +2 -2
- package/cjs/FieldObject/index.js +26 -15
- package/cjs/FieldObject/index.js.map +2 -2
- package/cjs/FormBuilder/index.js +11 -7
- package/cjs/FormBuilder/index.js.map +2 -2
- package/cjs/FormContext/index.js +7 -2
- package/cjs/FormContext.js.map +2 -2
- package/cjs/MultiplicityField/add-objects/index.js +2 -0
- 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/inputs/Checkboxes/index.js +2 -2
- package/cjs/inputs/Checkboxes/index.js.map +2 -2
- package/cjs/inputs/DateInput/index.js +41 -14
- package/cjs/inputs/DateInput/index.js.map +2 -2
- package/cjs/inputs/DateTimeInput/index.js +68 -34
- 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 +4 -4
- package/cjs/inputs/Input/index.js.map +2 -2
- package/cjs/inputs/Select/index.js +4 -3
- package/cjs/inputs/Select/index.js.map +2 -2
- package/cjs/inputs/inputsScenarios/index.js +2 -2
- package/cjs/inputs/inputsScenarios.js.map +2 -2
- package/cjs/lazy/index.js +2 -1
- package/cjs/lazy.js.map +2 -2
- package/cjs/registry/index.js +6 -6
- 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/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/index.js +5 -1
- package/cjs/validators/utils/index.js.map +2 -2
- package/index.js +1 -1
- package/inputs/AutoCompleteInput/AutoComplete.stories.d.ts +2 -0
- package/inputs/AutoCompleteInput/__stories__/Default.d.ts +1 -1
- package/inputs/AutoCompleteInput/__stories__/Multiple.d.ts +1 -1
- package/inputs/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.js +2 -2
- 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.js +42 -15
- 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.js +69 -35
- 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 +11 -4
- package/inputs/FileInput/index.js +57 -31
- package/inputs/FileInput/index.js.map +2 -2
- package/inputs/ImageInput/ImageInput.stories.d.ts +4 -1
- package/inputs/ImageInput/__stories__/Default.d.ts +1 -1
- package/inputs/ImageInput/__stories__/MaxSize.d.ts +1 -1
- package/inputs/ImageInput/__stories__/WithInitialValues.d.ts +3 -0
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension.d.ts +1 -1
- package/inputs/ImageInput/__stories__/logo.d/index.js +1 -0
- package/inputs/ImageInput/__stories__/logo.d/package.json +6 -0
- package/inputs/ImageInput/__stories__/logo.d.js.map +7 -0
- package/inputs/ImageInput/index.d.ts +9 -1
- 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 +2 -1
- package/inputs/Input/index.js +4 -4
- package/inputs/Input/index.js.map +2 -2
- package/inputs/Label/Label.stories.d.ts +2 -0
- package/inputs/Label/__stories__/Default.d.ts +1 -1
- package/inputs/OtpInput/OtpInput.stories.d.ts +2 -0
- package/inputs/OtpInput/__stories__/Default.d.ts +1 -1
- 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/Select/Select.stories.d.ts +2 -0
- package/inputs/Select/__stories__/Default.d.ts +1 -1
- package/inputs/Select/index.d.ts +2 -1
- package/inputs/Select/index.js +4 -3
- package/inputs/Select/index.js.map +2 -2
- package/inputs/inputsScenarios/index.js +2 -2
- package/inputs/inputsScenarios.d.ts +1 -1
- package/inputs/inputsScenarios.js.map +2 -2
- package/lazy/index.js +2 -1
- package/package.json +4 -4
- package/registry/index.js +6 -6
- package/src/Field/FieldBase.tsx +6 -1
- package/src/Field/FieldBaseContainer.tsx +68 -48
- package/src/Field/FieldConditional.tsx +4 -0
- package/src/Field/index.tsx +15 -5
- package/src/Field/types.tsx +11 -3
- package/src/Field/utils/index.ts +2 -0
- package/src/Field/utils/useField.ts +9 -1
- package/src/FieldArray/FormDialog.tsx +430 -243
- 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/index.tsx +53 -30
- package/src/FieldObject/index.tsx +33 -18
- 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/index.tsx +12 -7
- package/src/FormBuilder/scenarios.test.tsx +763 -5
- package/src/FormContext.tsx +5 -1
- 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 +2 -0
- package/src/MultiplicityField/index.tsx +3 -0
- package/src/MultiplicityField/types.ts +1 -0
- package/src/Questions/Questions.stories.js +3 -0
- package/src/Questions/__stories__/Default.tsx +1 -1
- 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/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.tsx +2 -6
- 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 +16 -0
- package/src/inputs/DateInput/index.tsx +46 -14
- 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 +16 -0
- package/src/inputs/DateTimeInput/index.tsx +73 -34
- 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 +4 -0
- package/src/inputs/FileInput/index.tsx +90 -48
- 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__/WithInitialValues.tsx +45 -0
- 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 +21 -17
- package/src/inputs/ImageInput/index.tsx +100 -48
- 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 +8 -0
- package/src/inputs/Input/index.tsx +5 -3
- package/src/inputs/Label/Label.stories.js +3 -0
- package/src/inputs/Label/__stories__/Default.tsx +1 -1
- package/src/inputs/OtpInput/OtpInput.stories.js +3 -0
- package/src/inputs/OtpInput/__stories__/Default.tsx +1 -1
- package/src/inputs/Radio/Radio.stories.js +3 -0
- package/src/inputs/Radio/__stories__/Conditional.tsx +1 -1
- package/src/inputs/Radio/__stories__/Default.tsx +1 -1
- package/src/inputs/Radio/__stories__/WithDivider.tsx +1 -1
- package/src/inputs/Select/Select.stories.js +3 -0
- package/src/inputs/Select/__stories__/Default.tsx +1 -1
- package/src/inputs/Select/index.tsx +7 -4
- package/src/inputs/inputsScenarios.ts +2 -2
- package/src/lazy.js +2 -1
- package/src/registry.js +6 -6
- package/src/types.tsx +2 -1
- package/src/utils.ts +27 -6
- package/src/validators/index.ts +17 -6
- package/src/validators/utils/amka.ts +39 -0
- package/src/validators/utils/date.ts +28 -4
- package/src/validators/utils/datetime.ts +121 -29
- package/src/validators/utils/file.ts +33 -19
- package/src/validators/utils/index.ts +4 -1
- package/types.d.ts +2 -1
- package/types.js.map +1 -1
- package/utils/index.js +20 -6
- package/utils.d.ts +2 -0
- package/utils.js.map +2 -2
- package/validators/index.d.ts +1 -1
- package/validators/index.js +12 -6
- package/validators/index.js.map +2 -2
- package/validators/utils/amka/index.js +36 -0
- package/{inputs/Input/inputsInputScenarios → 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 +1 -1
- package/validators/utils/date.js.map +2 -2
- package/validators/utils/datetime/index.js +118 -24
- package/validators/utils/datetime.d.ts +1 -1
- package/validators/utils/datetime.js.map +2 -2
- package/validators/utils/file/index.js +30 -17
- package/validators/utils/file.js.map +2 -2
- package/validators/utils/index.d.ts +1 -0
- package/validators/utils/index.js +4 -1
- package/validators/utils/index.js.map +2 -2
- package/cjs/inputs/Input/inputsInputScenarios/index.js +0 -439
- package/cjs/inputs/Input/inputsInputScenarios.js.map +0 -7
- 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/src/inputs/Input/inputsInputScenarios.ts +0 -404
|
@@ -22,6 +22,8 @@ const fields = [
|
|
|
22
22
|
secondary: 'Οι συνυπογράφοντες είναι άνθρωποι σαν και εμάς',
|
|
23
23
|
},
|
|
24
24
|
extra: {
|
|
25
|
+
noIndex: true,
|
|
26
|
+
border: false,
|
|
25
27
|
variant: 'dialog',
|
|
26
28
|
noHeader: false,
|
|
27
29
|
label: {
|
|
@@ -145,15 +147,14 @@ const fields = [
|
|
|
145
147
|
},
|
|
146
148
|
] as FieldSpec[];
|
|
147
149
|
|
|
148
|
-
export const WithModal = () => (
|
|
150
|
+
export const WithModal = (_: any) => (
|
|
149
151
|
<FormBuilder
|
|
150
152
|
onSubmit={(data) => {
|
|
151
153
|
console.log(data);
|
|
154
|
+
window.alert('Submit success');
|
|
152
155
|
}}
|
|
153
156
|
>
|
|
154
|
-
<Field name="string" {...fields[0]} />
|
|
155
157
|
<Field name="multiplicity" {...fields[1]} />
|
|
156
|
-
<Field name="arrayofafm" {...fields[2]} />
|
|
157
158
|
<Button>Συνέχεια</Button>
|
|
158
159
|
</FormBuilder>
|
|
159
160
|
);
|
package/src/FieldArray/index.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
2
|
import { ErrorOption, useFieldArray, UseFormReturn } from 'react-hook-form';
|
|
3
3
|
import { FieldBaseContainer } from '@digigov/form/Field/FieldBaseContainer';
|
|
4
4
|
import { FieldProps } from '@digigov/form/Field/types';
|
|
@@ -7,7 +7,6 @@ import { FieldObject } from '@digigov/form/FieldObject';
|
|
|
7
7
|
import { FieldsetLabel, Fieldset } from '@digigov/form/Fieldset';
|
|
8
8
|
import { Card } from '@digigov/ui/content/Card';
|
|
9
9
|
import { Button } from '@digigov/ui/form/Button';
|
|
10
|
-
import { Hint } from '@digigov/ui/typography/Hint';
|
|
11
10
|
|
|
12
11
|
export interface FieldArrayProps extends FieldProps {
|
|
13
12
|
control: UseFormReturn['control'];
|
|
@@ -19,6 +18,7 @@ export interface FieldArrayProps extends FieldProps {
|
|
|
19
18
|
getValues: UseFormReturn['getValues'];
|
|
20
19
|
setValue: UseFormReturn['setValue'];
|
|
21
20
|
reset: UseFormReturn['reset'];
|
|
21
|
+
resetField?: UseFormReturn['resetField'];
|
|
22
22
|
Field: React.FC<FieldProps>;
|
|
23
23
|
}
|
|
24
24
|
export const FieldArray: React.FC<FieldArrayProps> = ({
|
|
@@ -33,36 +33,55 @@ export const FieldArray: React.FC<FieldArrayProps> = ({
|
|
|
33
33
|
setValue,
|
|
34
34
|
layout,
|
|
35
35
|
reset,
|
|
36
|
+
resetField,
|
|
36
37
|
label,
|
|
37
38
|
Field,
|
|
38
39
|
...customField
|
|
39
40
|
}) => {
|
|
40
|
-
const {
|
|
41
|
+
const { append, remove } = useFieldArray({
|
|
41
42
|
control,
|
|
42
43
|
name,
|
|
43
44
|
});
|
|
45
|
+
const fields = getValues(name) || [];
|
|
46
|
+
|
|
47
|
+
/** The ref of the FieldBaseContainer. */
|
|
48
|
+
const containerRef = useRef<HTMLFieldSetElement | null>(null);
|
|
49
|
+
|
|
50
|
+
const { errors } = formState;
|
|
51
|
+
|
|
52
|
+
// Focus the fieldset when there are errors related to this field array
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
if (!containerRef.current) return;
|
|
55
|
+
const fieldErrors = Object.keys(errors);
|
|
56
|
+
// no errors
|
|
57
|
+
if (!fieldErrors.length) return;
|
|
58
|
+
|
|
59
|
+
if (
|
|
60
|
+
// Check if there are errors related to the current field array
|
|
61
|
+
fieldErrors.some((key) => {
|
|
62
|
+
const fieldArrayName = key.split('.')[0];
|
|
63
|
+
return fieldArrayName === name;
|
|
64
|
+
})
|
|
65
|
+
) {
|
|
66
|
+
if (containerRef.current && errors[name]) {
|
|
67
|
+
containerRef.current.focus();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}, [errors, name]);
|
|
44
71
|
|
|
45
72
|
return (
|
|
46
73
|
<FieldBaseContainer
|
|
47
74
|
label={label}
|
|
48
75
|
layout={layout}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
error?.message &&
|
|
53
|
-
error
|
|
54
|
-
? error
|
|
55
|
-
: undefined
|
|
56
|
-
}
|
|
76
|
+
register={register}
|
|
77
|
+
ref={containerRef}
|
|
78
|
+
error={error?.message && error ? error : undefined}
|
|
57
79
|
hasError={formState.isSubmitted && !formState.isSubmitting && !!error}
|
|
58
80
|
wrapper="fieldset"
|
|
59
81
|
name={name}
|
|
82
|
+
labelSize={customField.extra?.labelSize}
|
|
83
|
+
controlled={true}
|
|
60
84
|
>
|
|
61
|
-
{fields.length === 0 && (
|
|
62
|
-
<Hint {...customField.extra?.label.object?.nothing_added_props}>
|
|
63
|
-
{customField.extra?.label.object?.nothing_added}
|
|
64
|
-
</Hint>
|
|
65
|
-
)}
|
|
66
85
|
{customField.extra?.variant === 'dialog' ? (
|
|
67
86
|
<FormDialog
|
|
68
87
|
name={name}
|
|
@@ -78,6 +97,8 @@ export const FieldArray: React.FC<FieldArrayProps> = ({
|
|
|
78
97
|
label={label}
|
|
79
98
|
Field={Field}
|
|
80
99
|
reset={reset}
|
|
100
|
+
resetField={resetField}
|
|
101
|
+
sortable={customField.extra.sortable}
|
|
81
102
|
{...customField}
|
|
82
103
|
/>
|
|
83
104
|
) : (
|
|
@@ -85,7 +106,7 @@ export const FieldArray: React.FC<FieldArrayProps> = ({
|
|
|
85
106
|
{fields.map((field, index) => (
|
|
86
107
|
<Card
|
|
87
108
|
variant={customField.extra?.border ? 'border' : 'divider'}
|
|
88
|
-
key={field.id}
|
|
109
|
+
key={field.id || index}
|
|
89
110
|
>
|
|
90
111
|
<Fieldset>
|
|
91
112
|
<FieldsetLabel>
|
|
@@ -114,19 +135,21 @@ export const FieldArray: React.FC<FieldArrayProps> = ({
|
|
|
114
135
|
</Fieldset>
|
|
115
136
|
</Card>
|
|
116
137
|
))}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
ev
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
138
|
+
{customField.editable && (
|
|
139
|
+
<Button
|
|
140
|
+
type="button"
|
|
141
|
+
name={`${name}-add-object`}
|
|
142
|
+
color="secondary"
|
|
143
|
+
variant={customField.extra?.label.object?.addButtonVariant}
|
|
144
|
+
onClick={(ev) => {
|
|
145
|
+
ev.preventDefault();
|
|
146
|
+
append({});
|
|
147
|
+
}}
|
|
148
|
+
disabled={!customField?.editable}
|
|
149
|
+
>
|
|
150
|
+
{customField.extra?.label.object?.add}
|
|
151
|
+
</Button>
|
|
152
|
+
)}
|
|
130
153
|
</>
|
|
131
154
|
)}
|
|
132
155
|
</FieldBaseContainer>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useMemo } from 'react';
|
|
2
2
|
import { ErrorOption, UseFormReturn } from 'react-hook-form';
|
|
3
3
|
import { FieldBase } from '@digigov/form/Field/FieldBase';
|
|
4
|
-
import {
|
|
4
|
+
import { FieldProps, CalculatedField } from '@digigov/form/Field/types';
|
|
5
5
|
import {
|
|
6
6
|
FIELD_COMPONENTS,
|
|
7
7
|
ALTERNATIVE_COMPONENTS,
|
|
@@ -16,6 +16,7 @@ export interface FieldObjectProps extends Omit<FieldProps, 'key'> {
|
|
|
16
16
|
control: UseFormReturn['control'];
|
|
17
17
|
register: UseFormReturn['register'];
|
|
18
18
|
reset: UseFormReturn['reset'];
|
|
19
|
+
resetField: UseFormReturn['resetField'];
|
|
19
20
|
formState: UseFormReturn['formState'];
|
|
20
21
|
error?: ErrorOption;
|
|
21
22
|
defaultValue?: undefined;
|
|
@@ -29,6 +30,7 @@ export const FieldObject: React.FC<FieldObjectProps> = ({
|
|
|
29
30
|
control,
|
|
30
31
|
register,
|
|
31
32
|
reset,
|
|
33
|
+
resetField,
|
|
32
34
|
formState,
|
|
33
35
|
error,
|
|
34
36
|
defaultValue,
|
|
@@ -39,10 +41,12 @@ export const FieldObject: React.FC<FieldObjectProps> = ({
|
|
|
39
41
|
return (
|
|
40
42
|
<Fieldset>
|
|
41
43
|
{label?.primary && (
|
|
42
|
-
<FieldsetLegend size="sm"
|
|
44
|
+
<FieldsetLegend size="sm" marginBottom={3}>
|
|
45
|
+
{t(label.primary)}
|
|
46
|
+
</FieldsetLegend>
|
|
43
47
|
)}
|
|
44
48
|
{label?.secondary && (
|
|
45
|
-
<FieldsetCaption>{t(label.secondary)}</FieldsetCaption>
|
|
49
|
+
<FieldsetCaption marginBottom={3}>{t(label.secondary)}</FieldsetCaption>
|
|
46
50
|
)}
|
|
47
51
|
{extra?.fields.map((field) => (
|
|
48
52
|
<FieldObjectItem
|
|
@@ -51,10 +55,11 @@ export const FieldObject: React.FC<FieldObjectProps> = ({
|
|
|
51
55
|
control={control}
|
|
52
56
|
register={register}
|
|
53
57
|
reset={reset}
|
|
58
|
+
resetField={resetField}
|
|
54
59
|
field={field}
|
|
55
60
|
error={error && error[field.key]}
|
|
56
61
|
formState={formState}
|
|
57
|
-
defaultValue={defaultValue}
|
|
62
|
+
defaultValue={defaultValue?.[field.key] || undefined}
|
|
58
63
|
Field={Field}
|
|
59
64
|
/>
|
|
60
65
|
))}
|
|
@@ -63,15 +68,16 @@ export const FieldObject: React.FC<FieldObjectProps> = ({
|
|
|
63
68
|
};
|
|
64
69
|
|
|
65
70
|
export interface FieldObjectItemProps {
|
|
71
|
+
key: string;
|
|
66
72
|
name: string;
|
|
67
73
|
field: FieldSpec;
|
|
68
74
|
control: UseFormReturn['control'];
|
|
69
75
|
register: UseFormReturn['register'];
|
|
70
76
|
reset: UseFormReturn['reset'];
|
|
77
|
+
resetField: UseFormReturn['resetField'];
|
|
71
78
|
formState: UseFormReturn['formState'];
|
|
72
79
|
error?: ErrorOption;
|
|
73
80
|
children?: React.ReactNode;
|
|
74
|
-
// defaultValue?: FormData | undefined;
|
|
75
81
|
defaultValue?: undefined;
|
|
76
82
|
Field: React.FC<FieldProps>;
|
|
77
83
|
}
|
|
@@ -84,6 +90,7 @@ const FieldObjectItem: React.FC<FieldObjectItemProps> = ({
|
|
|
84
90
|
control,
|
|
85
91
|
formState,
|
|
86
92
|
reset,
|
|
93
|
+
resetField,
|
|
87
94
|
register,
|
|
88
95
|
defaultValue,
|
|
89
96
|
Field,
|
|
@@ -93,19 +100,27 @@ const FieldObjectItem: React.FC<FieldObjectItemProps> = ({
|
|
|
93
100
|
calculateField(children, field, FIELD_COMPONENTS, ALTERNATIVE_COMPONENTS),
|
|
94
101
|
[field]
|
|
95
102
|
);
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
103
|
+
if (Field) {
|
|
104
|
+
if (!field.type) {
|
|
105
|
+
field.type = 'string';
|
|
106
|
+
}
|
|
107
|
+
return <Field {...field} name={name} />;
|
|
108
|
+
} else {
|
|
109
|
+
const customError = error ? error : formState?.errors[name];
|
|
110
|
+
return (
|
|
111
|
+
<FieldBase
|
|
112
|
+
{...calculatedField}
|
|
113
|
+
name={name}
|
|
114
|
+
Field={Field}
|
|
115
|
+
control={control}
|
|
116
|
+
reset={reset}
|
|
117
|
+
resetField={resetField}
|
|
118
|
+
register={register}
|
|
119
|
+
error={customError}
|
|
120
|
+
defaultValue={defaultValue}
|
|
121
|
+
/>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
109
124
|
};
|
|
110
125
|
|
|
111
126
|
export default FieldObject;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import FormBuilder from '@digigov/form/FormBuilder';
|
|
2
|
+
import doc from './doc.mdx?raw';
|
|
2
3
|
export default {
|
|
3
4
|
title: 'Digigov Form/FormBuilder',
|
|
4
5
|
component: FormBuilder,
|
|
6
|
+
tags: ['autodocs'],
|
|
7
|
+
markdown: doc,
|
|
5
8
|
displayName: 'FormBuilder',
|
|
6
9
|
};
|
|
7
10
|
export { Default } from '@digigov/form/FormBuilder/__stories__/Default';
|
|
@@ -3,7 +3,7 @@ import FormBuilder, { Field } from '@digigov/form';
|
|
|
3
3
|
import { ErrorGroup } from '@digigov/form/Field/ErrorGroup';
|
|
4
4
|
import { Button } from '@digigov/ui/form/Button';
|
|
5
5
|
|
|
6
|
-
export const ErrorGrouping = () => (
|
|
6
|
+
export const ErrorGrouping = (_: any) => (
|
|
7
7
|
<FormBuilder
|
|
8
8
|
grid={true}
|
|
9
9
|
onSubmit={(data) => {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import React, { useCallback,
|
|
1
|
+
import React, { useCallback, useEffect, useRef } from 'react';
|
|
2
2
|
import { useForm } from 'react-hook-form';
|
|
3
3
|
import { Field } from '@digigov/form/Field';
|
|
4
4
|
import { ErrorGroup } from '@digigov/form/Field/ErrorGroup';
|
|
5
5
|
import { CONTROLLED_FIELD_COMPONENTS } from '@digigov/form/Field/utils';
|
|
6
6
|
import { FieldsetWithContext } from '@digigov/form/Fieldset/FieldsetWithContext';
|
|
7
|
-
import { FormContext } from '@digigov/form/FormContext';
|
|
7
|
+
import { FormContext, useFormContext } from '@digigov/form/FormContext';
|
|
8
8
|
import { FormBaseProps, FormData, FormBuilderProps } from '@digigov/form/types';
|
|
9
9
|
import { yupResolver } from '@digigov/form/utils';
|
|
10
10
|
import { useValidationSchema } from '@digigov/form/validators';
|
|
@@ -23,10 +23,11 @@ const FormBase = React.forwardRef(function FormBase(
|
|
|
23
23
|
mode,
|
|
24
24
|
initial,
|
|
25
25
|
reValidateMode,
|
|
26
|
-
shouldFocusError,
|
|
26
|
+
shouldFocusError = true,
|
|
27
27
|
criteriaMode,
|
|
28
28
|
componentRegistry,
|
|
29
29
|
grid,
|
|
30
|
+
errors,
|
|
30
31
|
...props
|
|
31
32
|
}: FormBaseProps,
|
|
32
33
|
ref: React.Ref<HTMLFormElement>
|
|
@@ -43,12 +44,18 @@ const FormBase = React.forwardRef(function FormBase(
|
|
|
43
44
|
const handleSubmit = useCallback(
|
|
44
45
|
(data: FormData): void => {
|
|
45
46
|
if (onSubmit) {
|
|
46
|
-
form.reset(data);
|
|
47
47
|
onSubmit(data);
|
|
48
48
|
}
|
|
49
49
|
},
|
|
50
50
|
[onSubmit]
|
|
51
51
|
);
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (errors) {
|
|
54
|
+
for (const fieldName in errors) {
|
|
55
|
+
form.setError(fieldName, errors[fieldName]);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}, [errors]);
|
|
52
59
|
const submit = form.handleSubmit(handleSubmit);
|
|
53
60
|
const ctx = {
|
|
54
61
|
fieldsMap,
|
|
@@ -72,6 +79,7 @@ const FormBase = React.forwardRef(function FormBase(
|
|
|
72
79
|
formRef: ref,
|
|
73
80
|
submit,
|
|
74
81
|
};
|
|
82
|
+
|
|
75
83
|
return (
|
|
76
84
|
<FormContext.Provider value={ctx}>
|
|
77
85
|
<Form grid={grid} onSubmit={submit} ref={ref} {...props}>
|
|
@@ -118,9 +126,6 @@ const groupFieldsByLayout = (fields) => {
|
|
|
118
126
|
return sizes;
|
|
119
127
|
}, {});
|
|
120
128
|
};
|
|
121
|
-
const useFormContext = () => {
|
|
122
|
-
return useContext(FormContext);
|
|
123
|
-
};
|
|
124
129
|
const useFormValues = () => {
|
|
125
130
|
const ctx = useFormContext();
|
|
126
131
|
return ctx.getValues();
|