@digigov/form 2.0.0-e7d30530 → 2.0.0-eaf330f5
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 +4 -3
- package/Field/FieldBase.js.map +2 -2
- package/Field/FieldBaseContainer/index.js +19 -37
- package/Field/FieldBaseContainer.d.ts +1 -1
- package/Field/FieldBaseContainer.js.map +2 -2
- package/Field/FieldConditional/index.js +1 -1
- package/Field/FieldConditional.js.map +1 -1
- package/Field/index.js +1 -2
- package/Field/index.js.map +2 -2
- package/Field/types.d.ts +2 -2
- package/Field/utils/index.js +3 -4
- package/Field/utils/index.js.map +2 -2
- package/FieldArray/FormDialog/index.js +7 -2
- package/FieldArray/FormDialog.d.ts +3 -2
- package/FieldArray/FormDialog.js.map +2 -2
- 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 -1
- package/FieldArray/index.js +88 -95
- package/FieldArray/index.js.map +3 -3
- package/FormBuilder/FormBuilder.stories.d.ts +0 -2
- 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 +7 -3
- package/FormBuilder/index.js.map +2 -2
- package/FormContext/index.js +2 -6
- package/FormContext.d.ts +0 -1
- package/FormContext.js.map +2 -2
- package/MultiplicityField/MultiplicityField.stories.d.ts +0 -2
- 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 +1 -1
- package/MultiplicityField/add-objects.js.map +2 -2
- package/MultiplicityField/index.js +2 -4
- package/MultiplicityField/index.js.map +2 -2
- package/MultiplicityField/types.d.ts +0 -1
- package/Questions/Questions.stories.d.ts +0 -2
- package/Questions/__stories__/Default.d.ts +1 -1
- package/cjs/Field/FieldBase/index.js +4 -3
- package/cjs/Field/FieldBase.js.map +2 -2
- package/cjs/Field/FieldBaseContainer/index.js +18 -36
- package/cjs/Field/FieldBaseContainer.js.map +3 -3
- package/cjs/Field/FieldConditional/index.js +1 -1
- package/cjs/Field/FieldConditional.js.map +1 -1
- package/cjs/Field/index.js +1 -2
- package/cjs/Field/index.js.map +2 -2
- package/cjs/Field/types.js.map +1 -1
- package/cjs/Field/utils/index.js +3 -4
- package/cjs/Field/utils/index.js.map +2 -2
- package/cjs/FieldArray/FormDialog/index.js +7 -2
- package/cjs/FieldArray/FormDialog.js.map +2 -2
- package/cjs/FieldArray/index.js +83 -93
- package/cjs/FieldArray/index.js.map +3 -3
- package/cjs/FormBuilder/index.js +7 -3
- package/cjs/FormBuilder/index.js.map +2 -2
- package/cjs/FormContext/index.js +2 -7
- package/cjs/FormContext.js.map +2 -2
- package/cjs/MultiplicityField/add-objects/index.js +1 -1
- package/cjs/MultiplicityField/add-objects.js.map +2 -2
- package/cjs/MultiplicityField/index.js +2 -4
- package/cjs/MultiplicityField/index.js.map +2 -2
- package/cjs/MultiplicityField/types.js.map +1 -1
- package/cjs/inputs/Checkboxes/index.js +1 -2
- package/cjs/inputs/Checkboxes/index.js.map +2 -2
- package/cjs/inputs/DateInput/index.js +12 -27
- package/cjs/inputs/DateInput/index.js.map +2 -2
- package/cjs/inputs/DateTimeInput/index.js +34 -55
- package/cjs/inputs/DateTimeInput/index.js.map +2 -2
- package/cjs/inputs/FileInput/index.js +26 -45
- package/cjs/inputs/FileInput/index.js.map +2 -2
- package/cjs/inputs/ImageInput/index.js +10 -41
- package/cjs/inputs/ImageInput/index.js.map +2 -2
- package/cjs/inputs/Input/inputsInputScenarios/index.js +439 -0
- package/cjs/inputs/Input/inputsInputScenarios.js.map +7 -0
- package/cjs/lazy/index.js +6 -6
- package/cjs/lazy.js.map +2 -2
- package/cjs/registry/index.js +10 -8
- package/cjs/registry.js.map +2 -2
- package/cjs/validators/index.js +10 -8
- package/cjs/validators/index.js.map +2 -2
- package/cjs/validators/utils/date/index.js +3 -21
- package/cjs/validators/utils/date.js.map +2 -2
- package/cjs/validators/utils/datetime/index.js +24 -113
- package/cjs/validators/utils/datetime.js.map +2 -2
- package/index.js +1 -1
- package/inputs/AutoCompleteInput/AutoComplete.stories.d.ts +0 -2
- 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 +0 -2
- 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 +1 -2
- package/inputs/Checkboxes/index.js.map +2 -2
- package/inputs/DateInput/DateInput.stories.d.ts +0 -6
- package/inputs/DateInput/__stories__/Default.d.ts +1 -1
- package/inputs/DateInput/index.js +13 -28
- package/inputs/DateInput/index.js.map +2 -2
- package/inputs/DateTimeInput/DateTimeInput.stories.d.ts +3 -10
- package/inputs/DateTimeInput/__stories__/Default.d.ts +1 -1
- package/inputs/DateTimeInput/index.js +35 -56
- package/inputs/DateTimeInput/index.js.map +2 -2
- package/inputs/FileInput/FileInput.stories.d.ts +0 -2
- package/inputs/FileInput/__stories__/Default.d.ts +1 -1
- package/inputs/FileInput/index.d.ts +1 -5
- package/inputs/FileInput/index.js +27 -46
- package/inputs/FileInput/index.js.map +2 -2
- package/inputs/ImageInput/ImageInput.stories.d.ts +1 -4
- package/inputs/ImageInput/__stories__/Default.d.ts +1 -1
- package/inputs/ImageInput/__stories__/MaxSize.d.ts +1 -1
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension.d.ts +1 -1
- package/inputs/ImageInput/index.d.ts +1 -9
- package/inputs/ImageInput/index.js +11 -42
- package/inputs/ImageInput/index.js.map +2 -2
- package/inputs/Input/Input.stories.d.ts +0 -3
- package/inputs/Input/__stories__/AFM.d.ts +1 -1
- package/inputs/Input/__stories__/Boolean.d.ts +1 -1
- 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/inputsInputScenarios/index.js +406 -0
- package/inputs/{ImageInput/__stories__/logo.d → 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 +0 -2
- package/inputs/Label/__stories__/Default.d.ts +1 -1
- package/inputs/OtpInput/OtpInput.stories.d.ts +0 -2
- package/inputs/OtpInput/__stories__/Default.d.ts +1 -1
- package/inputs/Radio/Radio.stories.d.ts +0 -2
- 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 +0 -2
- package/inputs/Select/__stories__/Default.d.ts +1 -1
- package/lazy/index.js +6 -6
- package/package.json +8 -8
- package/registry/index.js +10 -8
- package/src/Field/FieldBase.tsx +18 -14
- package/src/Field/FieldBaseContainer.tsx +51 -68
- package/src/Field/FieldConditional.tsx +1 -1
- package/src/Field/index.tsx +1 -2
- package/src/Field/types.tsx +2 -2
- package/src/Field/utils/index.ts +1 -2
- package/src/FieldArray/FormDialog.tsx +12 -3
- package/src/FieldArray/__stories__/Default.tsx +1 -1
- package/src/FieldArray/__stories__/WithExactLength.tsx +1 -1
- package/src/FieldArray/__stories__/WithModal.tsx +1 -1
- package/src/FieldArray/index.tsx +103 -111
- package/src/FormBuilder/FormBuilder.stories.js +0 -3
- 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 +7 -3
- package/src/FormBuilder/scenarios.test.tsx +1 -1
- package/src/FormContext.tsx +1 -5
- package/src/MultiplicityField/MultiplicityField.stories.js +0 -3
- 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 +1 -1
- package/src/MultiplicityField/index.tsx +1 -3
- package/src/MultiplicityField/types.ts +0 -1
- package/src/Questions/Questions.stories.js +0 -3
- package/src/Questions/__stories__/Default.tsx +1 -1
- package/src/inputs/AutoCompleteInput/AutoComplete.stories.js +0 -3
- 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 +0 -3
- 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 +5 -4
- package/src/inputs/DateInput/DateInput.stories.js +0 -7
- package/src/inputs/DateInput/__stories__/Default.tsx +1 -1
- package/src/inputs/DateInput/index.test.tsx +0 -16
- package/src/inputs/DateInput/index.tsx +13 -31
- package/src/inputs/DateTimeInput/DateTimeInput.stories.js +6 -12
- package/src/inputs/DateTimeInput/__stories__/Default.tsx +1 -1
- package/src/inputs/DateTimeInput/index.test.tsx +0 -16
- package/src/inputs/DateTimeInput/index.tsx +35 -59
- package/src/inputs/FileInput/FileInput.stories.js +0 -3
- package/src/inputs/FileInput/__stories__/Default.tsx +1 -1
- package/src/inputs/FileInput/index.tsx +39 -72
- package/src/inputs/ImageInput/ImageInput.stories.js +1 -5
- package/src/inputs/ImageInput/__stories__/Default.tsx +1 -1
- package/src/inputs/ImageInput/__stories__/MaxSize.tsx +2 -3
- package/src/inputs/ImageInput/__stories__/WithInvalidImageDimension.tsx +1 -1
- package/src/inputs/ImageInput/index.test.tsx +0 -4
- package/src/inputs/ImageInput/index.tsx +48 -100
- package/src/inputs/Input/Input.stories.js +0 -4
- package/src/inputs/Input/__stories__/AFM.tsx +1 -1
- package/src/inputs/Input/__stories__/Boolean.tsx +1 -1
- 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 +0 -8
- package/src/inputs/Input/inputsInputScenarios.ts +404 -0
- package/src/inputs/Label/Label.stories.js +0 -3
- package/src/inputs/Label/__stories__/Default.tsx +1 -1
- package/src/inputs/OtpInput/OtpInput.stories.js +0 -3
- package/src/inputs/OtpInput/__stories__/Default.tsx +1 -1
- package/src/inputs/Radio/Radio.stories.js +0 -3
- 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 +0 -3
- package/src/inputs/Select/__stories__/Default.tsx +1 -1
- package/src/lazy.js +6 -6
- package/src/registry.js +10 -8
- package/src/validators/index.ts +13 -13
- package/src/validators/utils/date.ts +4 -23
- package/src/validators/utils/datetime.ts +29 -116
- package/validators/index.js +10 -8
- package/validators/index.js.map +2 -2
- package/validators/utils/date/index.js +3 -21
- package/validators/utils/date.d.ts +1 -1
- package/validators/utils/date.js.map +2 -2
- package/validators/utils/datetime/index.js +24 -113
- package/validators/utils/datetime.d.ts +1 -1
- package/validators/utils/datetime.js.map +2 -2
- package/cjs/inputs/ImageInput/__stories__/logo.d/index.js +0 -1
- package/cjs/inputs/ImageInput/__stories__/logo.d.js.map +0 -7
- package/inputs/DateInput/__stories__/WithDefaultValue.d.ts +0 -3
- package/inputs/DateInput/__stories__/WithInitialValue.d.ts +0 -3
- package/inputs/DateInput/__stories__/WithWrongDefaultValue.d.ts +0 -3
- package/inputs/DateInput/__stories__/WithWrongInitialValue.d.ts +0 -3
- package/inputs/DateTimeInput/__stories__/WithDefaultValue.d.ts +0 -3
- package/inputs/DateTimeInput/__stories__/WithInitialValue.d.ts +0 -3
- package/inputs/DateTimeInput/__stories__/WithWrongDefaultValue.d.ts +0 -3
- package/inputs/DateTimeInput/__stories__/WithWrongInitialValue.d.ts +0 -3
- package/inputs/ImageInput/__stories__/WithInitialValues.d.ts +0 -3
- package/inputs/ImageInput/__stories__/logo.d/index.js +0 -1
- package/inputs/ImageInput/__stories__/logo.d.js.map +0 -7
- package/inputs/Input/__stories__/Email.d.ts +0 -3
- package/src/inputs/DateInput/__stories__/WithDefaultValue.tsx +0 -26
- package/src/inputs/DateInput/__stories__/WithInitialValue.tsx +0 -28
- package/src/inputs/DateInput/__stories__/WithWrongDefaultValue.tsx +0 -26
- package/src/inputs/DateInput/__stories__/WithWrongInitialValue.tsx +0 -28
- package/src/inputs/DateTimeInput/__stories__/WithDefaultValue.tsx +0 -26
- package/src/inputs/DateTimeInput/__stories__/WithInitialValue.tsx +0 -28
- package/src/inputs/DateTimeInput/__stories__/WithWrongDefaultValue.tsx +0 -26
- package/src/inputs/DateTimeInput/__stories__/WithWrongInitialValue.tsx +0 -28
- package/src/inputs/ImageInput/__stories__/WithInitialValues.tsx +0 -45
- package/src/inputs/ImageInput/__stories__/logo.d.ts +0 -4
- package/src/inputs/ImageInput/__stories__/logo.png +0 -0
- package/src/inputs/Input/__stories__/Email.tsx +0 -23
package/src/FieldArray/index.tsx
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import {
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Controller,
|
|
4
|
+
ErrorOption,
|
|
5
|
+
useFieldArray,
|
|
6
|
+
UseFormReturn,
|
|
7
|
+
} from 'react-hook-form';
|
|
3
8
|
import { FieldBaseContainer } from '@digigov/form/Field/FieldBaseContainer';
|
|
4
9
|
import { FieldProps } from '@digigov/form/Field/types';
|
|
5
10
|
import { FormDialog } from '@digigov/form/FieldArray/FormDialog';
|
|
@@ -18,7 +23,7 @@ export interface FieldArrayProps extends FieldProps {
|
|
|
18
23
|
getValues: UseFormReturn['getValues'];
|
|
19
24
|
setValue: UseFormReturn['setValue'];
|
|
20
25
|
reset: UseFormReturn['reset'];
|
|
21
|
-
resetField
|
|
26
|
+
resetField: UseFormReturn['resetField'];
|
|
22
27
|
Field: React.FC<FieldProps>;
|
|
23
28
|
}
|
|
24
29
|
export const FieldArray: React.FC<FieldArrayProps> = ({
|
|
@@ -42,117 +47,104 @@ export const FieldArray: React.FC<FieldArrayProps> = ({
|
|
|
42
47
|
control,
|
|
43
48
|
name,
|
|
44
49
|
});
|
|
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]);
|
|
71
50
|
|
|
51
|
+
const fields = getValues(name) || [];
|
|
72
52
|
return (
|
|
73
|
-
<
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
53
|
+
<Controller
|
|
54
|
+
render={({ field }) => {
|
|
55
|
+
return (
|
|
56
|
+
<FieldBaseContainer
|
|
57
|
+
label={label}
|
|
58
|
+
layout={layout}
|
|
59
|
+
register={register}
|
|
60
|
+
error={error?.message && error ? error : undefined}
|
|
61
|
+
hasError={
|
|
62
|
+
formState.isSubmitted && !formState.isSubmitting && !!error
|
|
63
|
+
}
|
|
64
|
+
wrapper="fieldset"
|
|
65
|
+
name={name}
|
|
66
|
+
labelSize={customField.extra?.labelSize}
|
|
67
|
+
>
|
|
68
|
+
<div tabIndex={-1} ref={field.ref} />
|
|
69
|
+
|
|
70
|
+
{customField.extra?.variant === 'dialog' ? (
|
|
71
|
+
<FormDialog
|
|
72
|
+
name={name}
|
|
73
|
+
trigger={trigger}
|
|
74
|
+
register={register}
|
|
75
|
+
clearErrors={clearErrors}
|
|
76
|
+
control={control}
|
|
77
|
+
formState={formState}
|
|
78
|
+
error={error}
|
|
79
|
+
getValues={getValues}
|
|
80
|
+
setValue={setValue}
|
|
81
|
+
layout={layout}
|
|
82
|
+
label={label}
|
|
83
|
+
Field={Field}
|
|
84
|
+
reset={reset}
|
|
85
|
+
resetField={resetField}
|
|
86
|
+
sortable={customField.extra.sortable}
|
|
87
|
+
{...customField}
|
|
88
|
+
/>
|
|
89
|
+
) : (
|
|
90
|
+
<>
|
|
91
|
+
{fields.map((field, index) => (
|
|
92
|
+
<Card
|
|
93
|
+
variant={customField.extra?.border ? 'border' : 'divider'}
|
|
94
|
+
key={field.id}
|
|
95
|
+
>
|
|
96
|
+
<Fieldset>
|
|
97
|
+
<FieldsetLabel>
|
|
98
|
+
{customField.extra?.label.object.title}{' '}
|
|
99
|
+
{!customField.extra?.noIndex && index + 1}
|
|
100
|
+
</FieldsetLabel>
|
|
101
|
+
<FieldObject
|
|
102
|
+
name={`${name}.${index}`}
|
|
103
|
+
error={Array.isArray(error) && error[index]}
|
|
104
|
+
formState={formState}
|
|
105
|
+
register={register}
|
|
106
|
+
control={control}
|
|
107
|
+
{...customField.extra?.of}
|
|
108
|
+
Field={Field}
|
|
109
|
+
/>
|
|
110
|
+
<Button
|
|
111
|
+
name={`${name}-object-remove`}
|
|
112
|
+
variant={
|
|
113
|
+
customField.extra?.label.object?.deleteButtonVariant
|
|
114
|
+
}
|
|
115
|
+
type="button"
|
|
116
|
+
color="warning"
|
|
117
|
+
onClick={() => remove(index)}
|
|
118
|
+
disabled={!customField?.editable}
|
|
119
|
+
>
|
|
120
|
+
{customField.extra?.label.object?.delete}
|
|
121
|
+
</Button>
|
|
122
|
+
</Fieldset>
|
|
123
|
+
</Card>
|
|
124
|
+
))}
|
|
125
|
+
{customField.editable && (
|
|
126
|
+
<Button
|
|
127
|
+
type="button"
|
|
128
|
+
name={`${name}-add-object`}
|
|
129
|
+
color="secondary"
|
|
130
|
+
variant={customField.extra?.label.object?.addButtonVariant}
|
|
131
|
+
onClick={(ev) => {
|
|
132
|
+
ev.preventDefault();
|
|
133
|
+
append({});
|
|
134
|
+
}}
|
|
135
|
+
disabled={!customField?.editable}
|
|
136
|
+
>
|
|
137
|
+
{customField.extra?.label.object?.add}
|
|
138
|
+
</Button>
|
|
139
|
+
)}
|
|
140
|
+
</>
|
|
141
|
+
)}
|
|
142
|
+
</FieldBaseContainer>
|
|
143
|
+
);
|
|
144
|
+
}}
|
|
145
|
+
control={control}
|
|
81
146
|
name={name}
|
|
82
|
-
|
|
83
|
-
controlled={true}
|
|
84
|
-
>
|
|
85
|
-
{customField.extra?.variant === 'dialog' ? (
|
|
86
|
-
<FormDialog
|
|
87
|
-
name={name}
|
|
88
|
-
trigger={trigger}
|
|
89
|
-
register={register}
|
|
90
|
-
clearErrors={clearErrors}
|
|
91
|
-
control={control}
|
|
92
|
-
formState={formState}
|
|
93
|
-
error={error}
|
|
94
|
-
getValues={getValues}
|
|
95
|
-
setValue={setValue}
|
|
96
|
-
layout={layout}
|
|
97
|
-
label={label}
|
|
98
|
-
Field={Field}
|
|
99
|
-
reset={reset}
|
|
100
|
-
resetField={resetField}
|
|
101
|
-
sortable={customField.extra.sortable}
|
|
102
|
-
{...customField}
|
|
103
|
-
/>
|
|
104
|
-
) : (
|
|
105
|
-
<>
|
|
106
|
-
{fields.map((field, index) => (
|
|
107
|
-
<Card
|
|
108
|
-
variant={customField.extra?.border ? 'border' : 'divider'}
|
|
109
|
-
key={field.id || index}
|
|
110
|
-
>
|
|
111
|
-
<Fieldset>
|
|
112
|
-
<FieldsetLabel>
|
|
113
|
-
{customField.extra?.label.object.title}{' '}
|
|
114
|
-
{!customField.extra?.noIndex && index + 1}
|
|
115
|
-
</FieldsetLabel>
|
|
116
|
-
<FieldObject
|
|
117
|
-
name={`${name}.${index}`}
|
|
118
|
-
error={Array.isArray(error) && error[index]}
|
|
119
|
-
formState={formState}
|
|
120
|
-
register={register}
|
|
121
|
-
control={control}
|
|
122
|
-
{...customField.extra?.of}
|
|
123
|
-
Field={Field}
|
|
124
|
-
/>
|
|
125
|
-
<Button
|
|
126
|
-
name={`${name}-object-remove`}
|
|
127
|
-
variant={customField.extra?.label.object?.deleteButtonVariant}
|
|
128
|
-
type="button"
|
|
129
|
-
color="warning"
|
|
130
|
-
onClick={() => remove(index)}
|
|
131
|
-
disabled={!customField?.editable}
|
|
132
|
-
>
|
|
133
|
-
{customField.extra?.label.object?.delete}
|
|
134
|
-
</Button>
|
|
135
|
-
</Fieldset>
|
|
136
|
-
</Card>
|
|
137
|
-
))}
|
|
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
|
-
)}
|
|
153
|
-
</>
|
|
154
|
-
)}
|
|
155
|
-
</FieldBaseContainer>
|
|
147
|
+
/>
|
|
156
148
|
);
|
|
157
149
|
};
|
|
158
150
|
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import FormBuilder from '@digigov/form/FormBuilder';
|
|
2
|
-
import doc from './doc.mdx?raw';
|
|
3
2
|
export default {
|
|
4
3
|
title: 'Digigov Form/FormBuilder',
|
|
5
4
|
component: FormBuilder,
|
|
6
|
-
tags: ['autodocs'],
|
|
7
|
-
markdown: doc,
|
|
8
5
|
displayName: 'FormBuilder',
|
|
9
6
|
};
|
|
10
7
|
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 = () => (
|
|
7
7
|
<FormBuilder
|
|
8
8
|
grid={true}
|
|
9
9
|
onSubmit={(data) => {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import React, { useCallback, useEffect, useRef } from 'react';
|
|
1
|
+
import React, { useCallback, useContext, 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
|
|
7
|
+
import { FormContext } 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';
|
|
@@ -44,6 +44,7 @@ const FormBase = React.forwardRef(function FormBase(
|
|
|
44
44
|
const handleSubmit = useCallback(
|
|
45
45
|
(data: FormData): void => {
|
|
46
46
|
if (onSubmit) {
|
|
47
|
+
form.reset(data);
|
|
47
48
|
onSubmit(data);
|
|
48
49
|
}
|
|
49
50
|
},
|
|
@@ -52,7 +53,7 @@ const FormBase = React.forwardRef(function FormBase(
|
|
|
52
53
|
useEffect(() => {
|
|
53
54
|
if (errors) {
|
|
54
55
|
for (const fieldName in errors) {
|
|
55
|
-
form.setError(fieldName, errors[fieldName]);
|
|
56
|
+
form.setError(fieldName, errors[fieldName], { shouldFocus: true });
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
59
|
}, [errors]);
|
|
@@ -126,6 +127,9 @@ const groupFieldsByLayout = (fields) => {
|
|
|
126
127
|
return sizes;
|
|
127
128
|
}, {});
|
|
128
129
|
};
|
|
130
|
+
const useFormContext = () => {
|
|
131
|
+
return useContext(FormContext);
|
|
132
|
+
};
|
|
129
133
|
const useFormValues = () => {
|
|
130
134
|
const ctx = useFormContext();
|
|
131
135
|
return ctx.getValues();
|
package/src/FormContext.tsx
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import React, { createContext
|
|
1
|
+
import React, { createContext } from 'react';
|
|
2
2
|
import { FormContextProps } from '@digigov/form/types';
|
|
3
3
|
|
|
4
4
|
export const FormContext: React.Context<FormContextProps> = createContext({
|
|
5
5
|
fieldsMap: {},
|
|
6
6
|
fieldsetsMap: {},
|
|
7
7
|
} as FormContextProps);
|
|
8
|
-
|
|
9
|
-
export const useFormContext = () => {
|
|
10
|
-
return useContext(FormContext);
|
|
11
|
-
};
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import MultiplicityField from '@digigov/form/MultiplicityField';
|
|
2
|
-
import doc from './doc.mdx?raw';
|
|
3
2
|
export default {
|
|
4
3
|
title: 'Digigov Form/MultiplicityField',
|
|
5
4
|
component: MultiplicityField,
|
|
6
|
-
tags: ['autodocs'],
|
|
7
|
-
markdown: doc,
|
|
8
5
|
displayName: 'MultiplicityField',
|
|
9
6
|
};
|
|
10
7
|
export { Default } from '@digigov/form/MultiplicityField/__stories__/Default';
|
|
@@ -47,7 +47,6 @@ export const AddObjects: React.FC<AddObjectsProps> = ({
|
|
|
47
47
|
setValue,
|
|
48
48
|
stashedObjects,
|
|
49
49
|
getValues,
|
|
50
|
-
resetField,
|
|
51
50
|
onStash,
|
|
52
51
|
error,
|
|
53
52
|
Field,
|
|
@@ -134,6 +133,7 @@ export const AddObjects: React.FC<AddObjectsProps> = ({
|
|
|
134
133
|
control,
|
|
135
134
|
register,
|
|
136
135
|
reset,
|
|
136
|
+
resetField,
|
|
137
137
|
error: needsMoreError,
|
|
138
138
|
} = useField(radioField.key, radioField?.type ? radioField : null);
|
|
139
139
|
|
|
@@ -31,7 +31,6 @@ export const Multiplicity: React.FC<MultiplicityProps> = ({
|
|
|
31
31
|
setValue,
|
|
32
32
|
getValues,
|
|
33
33
|
unregister,
|
|
34
|
-
resetField,
|
|
35
34
|
Field,
|
|
36
35
|
}) => {
|
|
37
36
|
const { fields, append, remove } = useFieldArray({
|
|
@@ -53,6 +52,7 @@ export const Multiplicity: React.FC<MultiplicityProps> = ({
|
|
|
53
52
|
<FieldBaseContainer
|
|
54
53
|
label={label}
|
|
55
54
|
layout={layout}
|
|
55
|
+
register={register}
|
|
56
56
|
error={
|
|
57
57
|
formState.isSubmitted && !formState.isSubmitting && error?.message
|
|
58
58
|
? error
|
|
@@ -61,7 +61,6 @@ export const Multiplicity: React.FC<MultiplicityProps> = ({
|
|
|
61
61
|
hasError={formState.isSubmitted && !formState.isSubmitting && !!error}
|
|
62
62
|
wrapper="fieldset"
|
|
63
63
|
name={name}
|
|
64
|
-
register={register}
|
|
65
64
|
>
|
|
66
65
|
{stashedObjects.length > 0 ? (
|
|
67
66
|
<div>
|
|
@@ -100,7 +99,6 @@ export const Multiplicity: React.FC<MultiplicityProps> = ({
|
|
|
100
99
|
getValues={getValues}
|
|
101
100
|
unregister={unregister}
|
|
102
101
|
trigger={trigger}
|
|
103
|
-
resetField={resetField}
|
|
104
102
|
clearErrors={clearErrors}
|
|
105
103
|
Field={Field}
|
|
106
104
|
/>
|
|
@@ -12,7 +12,6 @@ export interface MultiplicityProps
|
|
|
12
12
|
setValue: UseFormReturn['setValue'];
|
|
13
13
|
getValues: UseFormReturn['getValues'];
|
|
14
14
|
unregister: UseFormReturn['unregister'];
|
|
15
|
-
resetField?: UseFormReturn['resetField'];
|
|
16
15
|
error?: ErrorOption;
|
|
17
16
|
extra?: Record<string, any>;
|
|
18
17
|
label?: FieldSpec['label'];
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import Questions from '@digigov/form/Questions';
|
|
2
|
-
import doc from './doc.mdx?raw';
|
|
3
2
|
export default {
|
|
4
3
|
title: 'Digigov Form/Questions',
|
|
5
4
|
component: Questions,
|
|
6
|
-
tags: ['autodocs'],
|
|
7
|
-
markdown: doc,
|
|
8
5
|
displayName: 'Questions',
|
|
9
6
|
};
|
|
10
7
|
export { Default } from '@digigov/form/Questions/__stories__/Default';
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import AutoComplete from '@digigov/form/inputs/AutoCompleteInput';
|
|
2
|
-
import doc from './doc.mdx?raw';
|
|
3
2
|
export default {
|
|
4
3
|
title: 'Digigov Form/inputs/AutoCompleteInput',
|
|
5
4
|
component: AutoComplete,
|
|
6
|
-
tags: ['autodocs'],
|
|
7
|
-
markdown: doc,
|
|
8
5
|
displayName: 'AutoCompleteInput',
|
|
9
6
|
};
|
|
10
7
|
export { Default } from '@digigov/form/inputs/AutoCompleteInput/__stories__/Default';
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import Checkboxes from '@digigov/form/inputs/Checkboxes';
|
|
2
|
-
import doc from './doc.mdx?raw';
|
|
3
2
|
export default {
|
|
4
3
|
title: 'Digigov Form/inputs/Checkboxes',
|
|
5
4
|
component: Checkboxes,
|
|
6
|
-
tags: ['autodocs'],
|
|
7
|
-
markdown: doc,
|
|
8
5
|
displayName: 'Checkboxes',
|
|
9
6
|
};
|
|
10
7
|
export { Default } from '@digigov/form/inputs/Checkboxes/__stories__/Default';
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import FormBuilder, { Field } from '@digigov/form';
|
|
3
3
|
import { Button } from '@digigov/ui/form/Button';
|
|
4
4
|
|
|
5
|
-
export const WithDivider = (
|
|
5
|
+
export const WithDivider = () => (
|
|
6
6
|
<FormBuilder
|
|
7
7
|
onSubmit={(data) => {
|
|
8
8
|
console.log(data);
|
|
@@ -32,10 +32,14 @@ export const Checkboxes: React.FC<CheckboxesProps> = ({
|
|
|
32
32
|
const handleChange =
|
|
33
33
|
(optionValue, idx, show) =>
|
|
34
34
|
(evt): void => {
|
|
35
|
-
let newValue
|
|
35
|
+
let newValue;
|
|
36
36
|
if (evt.currentTarget.checked) {
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
38
|
+
// @ts-ignore
|
|
37
39
|
newValue = value.concat([optionValue]);
|
|
38
40
|
} else {
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
42
|
+
// @ts-ignore
|
|
39
43
|
newValue = value.filter((val) => val !== optionValue);
|
|
40
44
|
}
|
|
41
45
|
if (show && show.length > 0) {
|
|
@@ -44,9 +48,6 @@ export const Checkboxes: React.FC<CheckboxesProps> = ({
|
|
|
44
48
|
);
|
|
45
49
|
}
|
|
46
50
|
|
|
47
|
-
// reset value to undefined instead of an empty array
|
|
48
|
-
// so the error state mechanism can throw validation errors
|
|
49
|
-
if (newValue.length === 0) newValue = undefined;
|
|
50
51
|
onChange(newValue);
|
|
51
52
|
};
|
|
52
53
|
const { t } = useTranslation();
|
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import DateInput from '@digigov/form/inputs/DateInput';
|
|
2
|
-
import doc from './doc.mdx?raw';
|
|
3
2
|
export default {
|
|
4
3
|
title: 'Digigov Form/inputs/DateInput',
|
|
5
4
|
component: DateInput,
|
|
6
|
-
tags: ['autodocs'],
|
|
7
|
-
markdown: doc,
|
|
8
5
|
displayName: 'DateInput',
|
|
9
6
|
};
|
|
10
7
|
export { Default } from '@digigov/form/inputs/DateInput/__stories__/Default';
|
|
11
|
-
export { WithDefaultValue } from '@digigov/form/inputs/DateInput/__stories__/WithDefaultValue';
|
|
12
|
-
export { WithWrongDefaultValue } from '@digigov/form/inputs/DateInput/__stories__/WithWrongDefaultValue';
|
|
13
|
-
export { WithInitialValue } from '@digigov/form/inputs/DateInput/__stories__/WithInitialValue';
|
|
14
|
-
export { WithWrongInitialValue } from '@digigov/form/inputs/DateInput/__stories__/WithWrongInitialValue';
|
|
@@ -14,7 +14,7 @@ const fields = [
|
|
|
14
14
|
} as const,
|
|
15
15
|
];
|
|
16
16
|
|
|
17
|
-
export const Default = (
|
|
17
|
+
export const Default = () => (
|
|
18
18
|
<FormBuilder onSubmit={() => console.log('kati')}>
|
|
19
19
|
{fields.map(({ key, ...field }) => {
|
|
20
20
|
return <Field {...field} name={key} key={key} />;
|
|
@@ -2,10 +2,6 @@ import React from 'react';
|
|
|
2
2
|
import { test, expect } from '@playwright/experimental-ct-react';
|
|
3
3
|
import TestVariant from '@digigov/ui/utils/TestVariant'
|
|
4
4
|
import { Default } from '@digigov/form/inputs/DateInput/__stories__/Default';
|
|
5
|
-
import { WithDefaultValue } from '@digigov/form/inputs/DateInput/__stories__/WithDefaultValue';
|
|
6
|
-
import { WithInitialValue } from '@digigov/form/inputs/DateInput/__stories__/WithInitialValue';
|
|
7
|
-
import { WithWrongDefaultValue } from '@digigov/form/inputs/DateInput/__stories__/WithWrongDefaultValue';
|
|
8
|
-
import { WithWrongInitialValue } from '@digigov/form/inputs/DateInput/__stories__/WithWrongInitialValue';
|
|
9
5
|
|
|
10
6
|
test('renders the All DateInput variants', async ({ mount, page }) => {
|
|
11
7
|
await mount(
|
|
@@ -14,18 +10,6 @@ test('renders the All DateInput variants', async ({ mount, page }) => {
|
|
|
14
10
|
<TestVariant title="Default">
|
|
15
11
|
<Default />
|
|
16
12
|
</TestVariant>
|
|
17
|
-
<TestVariant title="WithDefaultValue">
|
|
18
|
-
<WithDefaultValue />
|
|
19
|
-
</TestVariant>
|
|
20
|
-
<TestVariant title="WithInitialValue">
|
|
21
|
-
<WithInitialValue />
|
|
22
|
-
</TestVariant>
|
|
23
|
-
<TestVariant title="WithWrongDefaultValue">
|
|
24
|
-
<WithWrongDefaultValue />
|
|
25
|
-
</TestVariant>
|
|
26
|
-
<TestVariant title="WithWrongInitialValue">
|
|
27
|
-
<WithWrongInitialValue />
|
|
28
|
-
</TestVariant>
|
|
29
13
|
</div>
|
|
30
14
|
)
|
|
31
15
|
await page.evaluate(() => document.fonts.ready);
|