@digigov/form 0.12.6 → 0.13.0
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/CHANGELOG.md +15 -4
- package/Field/FieldBase.js +2 -2
- package/Field/FieldBaseContainer.js +7 -7
- package/Field/FieldConditional.js +10 -5
- package/Field/types.d.ts +2 -1
- package/Field/utils.js +14 -10
- package/FieldArray/index.js +3 -3
- package/FieldObject/index.d.ts +1 -1
- package/FieldObject/index.js +4 -4
- package/Fieldset/FieldsetWithContext.js +4 -4
- package/Fieldset/index.d.ts +1 -1
- package/Fieldset/index.js +2 -2
- package/FormBuilder/FormBuilder.js +5 -5
- package/FormContext.d.ts +1 -1
- package/MultiplicityField/__stories__/PreviewDisplay.js +3 -3
- package/MultiplicityField/add-objects.js +6 -6
- package/MultiplicityField/index.d.ts +2 -2
- package/MultiplicityField/index.js +5 -5
- package/Questions/Questions.js +2 -2
- package/Questions/Step/ReviewStep.js +7 -7
- package/Questions/Step/Step.js +2 -2
- package/Questions/Step/StepArrayReview.js +10 -10
- package/Questions/Step/StepDescription.js +2 -2
- package/Questions/Step/StepForm.d.ts +1 -1
- package/Questions/Step/StepForm.js +5 -5
- package/Questions/Step/StepTitle.js +2 -2
- package/Questions/Step/getAddMoreFields.d.ts +1 -1
- package/Questions/__stories__/Default.js +6 -6
- package/Questions/index.spec.js +2 -2
- package/es/Field/FieldBase.js +1 -1
- package/es/Field/FieldBaseContainer.js +4 -4
- package/es/Field/FieldConditional.js +6 -2
- package/es/Field/utils.js +13 -9
- package/es/FieldArray/index.js +2 -2
- package/es/FieldObject/index.js +2 -2
- package/es/Fieldset/FieldsetWithContext.js +2 -2
- package/es/Fieldset/index.js +1 -1
- package/es/FormBuilder/FormBuilder.js +3 -3
- package/es/FormContext.js +1 -1
- package/es/MultiplicityField/__stories__/PreviewDisplay.js +2 -2
- package/es/MultiplicityField/add-objects.js +5 -5
- package/es/MultiplicityField/index.js +3 -3
- package/es/Questions/Questions.js +1 -1
- package/es/Questions/Step/ReviewStep.js +4 -4
- package/es/Questions/Step/Step.js +1 -1
- package/es/Questions/Step/StepArrayReview.js +6 -6
- package/es/Questions/Step/StepDescription.js +1 -1
- package/es/Questions/Step/StepForm.js +4 -4
- package/es/Questions/Step/StepTitle.js +1 -1
- package/es/Questions/__stories__/Default.js +4 -4
- package/es/Questions/index.spec.js +2 -1
- package/es/inputs/AutoComplete/__stories__/Default.js +2 -2
- package/es/inputs/AutoComplete/index.js +1 -1
- package/es/inputs/Checkboxes/Checkboxes.stories.js +3 -1
- package/es/inputs/Checkboxes/Checkboxes.stories.playwright.json +16 -0
- package/es/inputs/Checkboxes/__stories__/Conditional.js +95 -0
- package/es/inputs/Checkboxes/__stories__/WithDivider.js +43 -0
- package/es/inputs/Checkboxes/index.js +45 -13
- package/es/inputs/DateInput/index.js +1 -1
- package/es/inputs/FileInput/index.js +4 -4
- package/es/inputs/Input/Input.stories.js +2 -1
- package/es/inputs/Input/__stories__/TextWithCharacterLimit.js +31 -0
- package/es/inputs/Input/index.js +23 -5
- package/es/inputs/Label/index.js +1 -1
- package/es/inputs/Radio/Radio.stories.js +3 -1
- package/es/inputs/Radio/Radio.stories.playwright.json +16 -0
- package/es/inputs/Radio/__stories__/Conditional.js +95 -0
- package/es/inputs/Radio/__stories__/WithDivider.js +48 -0
- package/es/inputs/Radio/index.js +17 -6
- package/es/registry.js +3 -0
- package/es/utils.js +1 -1
- package/es/validators/index.js +10 -2
- package/es/validators/utils/index.js +16 -2
- package/es/validators/utils/text_limit.js +54 -0
- package/esm/Field/FieldBase.js +1 -1
- package/esm/Field/FieldBaseContainer.js +4 -4
- package/esm/Field/FieldConditional.js +6 -2
- package/esm/Field/utils.js +13 -9
- package/esm/FieldArray/index.js +2 -2
- package/esm/FieldObject/index.js +2 -2
- package/esm/Fieldset/FieldsetWithContext.js +2 -2
- package/esm/Fieldset/index.js +1 -1
- package/esm/FormBuilder/FormBuilder.js +3 -3
- package/esm/FormContext.js +1 -1
- package/esm/MultiplicityField/__stories__/PreviewDisplay.js +2 -2
- package/esm/MultiplicityField/add-objects.js +5 -5
- package/esm/MultiplicityField/index.js +3 -3
- package/esm/Questions/Questions.js +1 -1
- package/esm/Questions/Step/ReviewStep.js +4 -4
- package/esm/Questions/Step/Step.js +1 -1
- package/esm/Questions/Step/StepArrayReview.js +6 -6
- package/esm/Questions/Step/StepDescription.js +1 -1
- package/esm/Questions/Step/StepForm.js +4 -4
- package/esm/Questions/Step/StepTitle.js +1 -1
- package/esm/Questions/__stories__/Default.js +4 -4
- package/esm/Questions/index.spec.js +2 -1
- package/esm/index.js +1 -1
- package/esm/inputs/AutoComplete/__stories__/Default.js +2 -2
- package/esm/inputs/AutoComplete/index.js +1 -1
- package/esm/inputs/Checkboxes/Checkboxes.stories.js +3 -1
- package/esm/inputs/Checkboxes/Checkboxes.stories.playwright.json +16 -0
- package/esm/inputs/Checkboxes/__stories__/Conditional.js +95 -0
- package/esm/inputs/Checkboxes/__stories__/WithDivider.js +43 -0
- package/esm/inputs/Checkboxes/index.js +45 -13
- package/esm/inputs/DateInput/index.js +1 -1
- package/esm/inputs/FileInput/index.js +4 -4
- package/esm/inputs/Input/Input.stories.js +2 -1
- package/esm/inputs/Input/__stories__/TextWithCharacterLimit.js +31 -0
- package/esm/inputs/Input/index.js +23 -5
- package/esm/inputs/Label/index.js +1 -1
- package/esm/inputs/Radio/Radio.stories.js +3 -1
- package/esm/inputs/Radio/Radio.stories.playwright.json +16 -0
- package/esm/inputs/Radio/__stories__/Conditional.js +95 -0
- package/esm/inputs/Radio/__stories__/WithDivider.js +48 -0
- package/esm/inputs/Radio/index.js +17 -6
- package/esm/registry.js +3 -0
- package/esm/utils.js +1 -1
- package/esm/validators/index.js +10 -2
- package/esm/validators/utils/index.js +16 -2
- package/esm/validators/utils/text_limit.js +54 -0
- package/inputs/AutoComplete/__stories__/Default.js +3 -3
- package/inputs/AutoComplete/index.d.ts +2 -2
- package/inputs/AutoComplete/index.js +2 -2
- package/inputs/Checkboxes/Checkboxes.stories.d.ts +2 -0
- package/inputs/Checkboxes/Checkboxes.stories.js +28 -0
- package/inputs/Checkboxes/Checkboxes.stories.playwright.json +16 -0
- package/inputs/Checkboxes/__stories__/Conditional.d.ts +1 -0
- package/inputs/Checkboxes/__stories__/Conditional.js +115 -0
- package/inputs/Checkboxes/__stories__/WithDivider.d.ts +2 -0
- package/inputs/Checkboxes/__stories__/WithDivider.js +63 -0
- package/inputs/Checkboxes/index.d.ts +1 -1
- package/inputs/Checkboxes/index.js +53 -13
- package/inputs/DateInput/index.js +2 -2
- package/inputs/FileInput/index.js +5 -5
- package/inputs/Input/Input.stories.d.ts +1 -0
- package/inputs/Input/Input.stories.js +14 -0
- package/inputs/Input/__stories__/TextWithCharacterLimit.d.ts +2 -0
- package/inputs/Input/__stories__/TextWithCharacterLimit.js +51 -0
- package/inputs/Input/index.d.ts +4 -0
- package/inputs/Input/index.js +26 -5
- package/inputs/Label/index.d.ts +2 -0
- package/inputs/Label/index.js +2 -2
- package/inputs/Radio/Radio.stories.d.ts +2 -0
- package/inputs/Radio/Radio.stories.js +28 -0
- package/inputs/Radio/Radio.stories.playwright.json +16 -0
- package/inputs/Radio/__stories__/Conditional.d.ts +1 -0
- package/inputs/Radio/__stories__/Conditional.js +115 -0
- package/inputs/Radio/__stories__/WithDivider.d.ts +2 -0
- package/inputs/Radio/__stories__/WithDivider.js +68 -0
- package/inputs/Radio/index.d.ts +1 -1
- package/inputs/Radio/index.js +20 -8
- package/inputs/Select/index.d.ts +1 -1
- package/package.json +3 -3
- package/registry.d.ts +1 -0
- package/registry.js +4 -0
- package/src/Field/FieldBase.tsx +1 -1
- package/src/Field/FieldBaseContainer.tsx +5 -5
- package/src/Field/FieldConditional.tsx +9 -3
- package/src/Field/index.tsx +1 -1
- package/src/Field/types.tsx +2 -1
- package/src/Field/utils.ts +17 -11
- package/src/FieldArray/index.tsx +3 -3
- package/src/FieldObject/index.tsx +5 -5
- package/src/Fieldset/FieldsetWithContext.tsx +3 -3
- package/src/Fieldset/index.tsx +5 -5
- package/src/FormBuilder/FormBuilder.tsx +4 -4
- package/src/FormContext.tsx +2 -1
- package/src/MultiplicityField/__stories__/PreviewDisplay.tsx +6 -6
- package/src/MultiplicityField/add-objects.tsx +4 -4
- package/src/MultiplicityField/index.tsx +5 -5
- package/src/Questions/Questions.tsx +2 -2
- package/src/Questions/Step/ReviewStep.tsx +5 -5
- package/src/Questions/Step/Step.tsx +1 -1
- package/src/Questions/Step/StepArrayReview.tsx +8 -8
- package/src/Questions/Step/StepDescription.tsx +1 -1
- package/src/Questions/Step/StepForm.tsx +5 -5
- package/src/Questions/Step/StepTitle.tsx +1 -1
- package/src/Questions/Step/getAddMoreFields.tsx +1 -1
- package/src/Questions/__stories__/Default.tsx +4 -4
- package/src/Questions/index.spec.tsx +2 -1
- package/src/inputs/AutoComplete/__stories__/Default.tsx +2 -2
- package/src/inputs/AutoComplete/index.tsx +3 -3
- package/src/inputs/Checkboxes/Checkboxes.stories.js +2 -0
- package/src/inputs/Checkboxes/Checkboxes.stories.playwright.json +16 -0
- package/src/inputs/Checkboxes/__stories__/Conditional.tsx +100 -0
- package/src/inputs/Checkboxes/__stories__/WithDivider.tsx +39 -0
- package/src/inputs/Checkboxes/index.tsx +61 -31
- package/src/inputs/DateInput/index.tsx +2 -2
- package/src/inputs/FileInput/index.tsx +4 -4
- package/src/inputs/Input/Input.stories.js +2 -1
- package/src/inputs/Input/__stories__/TextWithCharacterLimit.tsx +24 -0
- package/src/inputs/Input/index.tsx +57 -16
- package/src/inputs/Label/index.tsx +4 -2
- package/src/inputs/OtpInput/__stories__/Default.tsx +1 -1
- package/src/inputs/Radio/Radio.stories.js +3 -0
- package/src/inputs/Radio/Radio.stories.playwright.json +16 -0
- package/src/inputs/Radio/__stories__/Conditional.tsx +97 -0
- package/src/inputs/Radio/__stories__/WithDivider.tsx +42 -0
- package/src/inputs/Radio/index.tsx +22 -5
- package/src/inputs/Select/index.tsx +2 -2
- package/src/registry.js +3 -0
- package/src/types.tsx +6 -4
- package/src/utils.ts +1 -1
- package/src/validators/index.ts +8 -1
- package/src/validators/utils/file.ts +1 -1
- package/src/validators/utils/index.ts +10 -1
- package/src/validators/utils/phone.ts +1 -1
- package/src/validators/utils/postal_code.ts +1 -1
- package/src/validators/utils/text_limit.ts +44 -0
- package/types.d.ts +6 -4
- package/validators/index.js +9 -1
- package/validators/utils/file.d.ts +1 -1
- package/validators/utils/index.d.ts +1 -0
- package/validators/utils/index.js +29 -2
- package/validators/utils/phone.d.ts +1 -1
- package/validators/utils/postal_code.d.ts +1 -1
- package/validators/utils/text_limit.d.ts +4 -0
- package/validators/utils/text_limit.js +65 -0
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { UncontrolledFieldProps } from '@digigov/form/Field/types';
|
|
3
|
-
import TextArea from '@digigov/react-core/TextArea';
|
|
4
2
|
import TextInput from '@digigov/react-core/TextInput';
|
|
3
|
+
import TextArea from '@digigov/react-core/TextArea';
|
|
4
|
+
import { Hint } from '@digigov/react-core';
|
|
5
|
+
import { UncontrolledFieldProps } from '@digigov/form/Field/types';
|
|
6
|
+
import { useWatch } from 'react-hook-form';
|
|
7
|
+
import { useTranslation } from '@digigov/ui/app/i18n';
|
|
5
8
|
|
|
6
9
|
const TYPES_MAP = {
|
|
7
10
|
string: 'text',
|
|
@@ -17,12 +20,17 @@ export interface InputProps extends Omit<UncontrolledFieldProps, 'extra'> {
|
|
|
17
20
|
className?: string;
|
|
18
21
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
22
|
rows?: any;
|
|
23
|
+
limit: {
|
|
24
|
+
min?: number;
|
|
25
|
+
max?: number;
|
|
26
|
+
};
|
|
20
27
|
};
|
|
21
28
|
}
|
|
22
29
|
|
|
23
30
|
export const Input: React.ExoticComponent<InputProps> = React.forwardRef(
|
|
24
|
-
function WrappedInput({ name, type, extra, ...props }, ref: never) {
|
|
25
|
-
|
|
31
|
+
function WrappedInput({ name, control, type, extra, ...props }, ref: never) {
|
|
32
|
+
// eslint-disable-next-line prefer-const
|
|
33
|
+
let { multiline = false, rows, limit } = extra || {};
|
|
26
34
|
const { className } = extra || {};
|
|
27
35
|
// if enforced to multiline use true. Derive from type otherwise.
|
|
28
36
|
multiline = multiline === true || type === 'text';
|
|
@@ -30,20 +38,53 @@ export const Input: React.ExoticComponent<InputProps> = React.forwardRef(
|
|
|
30
38
|
rows = rows || (multiline ? 4 : 1);
|
|
31
39
|
// translate dilosi type to HTML Input type
|
|
32
40
|
const fieldType = TYPES_MAP[type || 'text'] || 'text';
|
|
41
|
+
const { t } = useTranslation();
|
|
42
|
+
const currentValue: string | '' = useWatch({ control, name });
|
|
33
43
|
if (multiline === true) {
|
|
34
44
|
return (
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
...
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
<>
|
|
46
|
+
<TextArea
|
|
47
|
+
name={name}
|
|
48
|
+
className={className}
|
|
49
|
+
rows={rows}
|
|
50
|
+
ref={ref}
|
|
51
|
+
{...{
|
|
52
|
+
...props,
|
|
53
|
+
reset: undefined,
|
|
54
|
+
required: undefined,
|
|
55
|
+
type: fieldType,
|
|
56
|
+
}}
|
|
57
|
+
/>
|
|
58
|
+
{limit?.max && (
|
|
59
|
+
<Hint>
|
|
60
|
+
{currentValue === undefined ||
|
|
61
|
+
(currentValue?.length >= 0 &&
|
|
62
|
+
currentValue?.length <= limit?.max) ? (
|
|
63
|
+
<span>
|
|
64
|
+
{t('form.info.text.you_have')}{' '}
|
|
65
|
+
<b>
|
|
66
|
+
{!currentValue
|
|
67
|
+
? limit.max
|
|
68
|
+
: limit?.max - currentValue?.length}
|
|
69
|
+
</b>{' '}
|
|
70
|
+
{currentValue && limit?.max - currentValue?.length === 1
|
|
71
|
+
? `${t('form.info.text.character')}`
|
|
72
|
+
: `${t('form.info.text.characters')}`}{' '}
|
|
73
|
+
{t('form.info.text.remaining')}.
|
|
74
|
+
</span>
|
|
75
|
+
) : (
|
|
76
|
+
<span style={{ color: '#b60202' }}>
|
|
77
|
+
{t('form.info.text.you_have')}{' '}
|
|
78
|
+
<b>{currentValue && currentValue?.length - limit?.max}</b>{' '}
|
|
79
|
+
{currentValue?.length - limit?.max === 1
|
|
80
|
+
? `${t('form.info.text.character')}`
|
|
81
|
+
: `${t('form.info.text.characters')}`}{' '}
|
|
82
|
+
{t('form.info.text.too_many')}.
|
|
83
|
+
</span>
|
|
84
|
+
)}
|
|
85
|
+
</Hint>
|
|
86
|
+
)}
|
|
87
|
+
</>
|
|
47
88
|
);
|
|
48
89
|
} else {
|
|
49
90
|
return (
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { FieldLabelProps } from '@digigov/form/types';
|
|
3
|
-
import Hint from '@digigov/react-core/Hint';
|
|
4
2
|
import LabelTitle from '@digigov/react-core/LabelTitle';
|
|
3
|
+
import Hint from '@digigov/react-core/Hint';
|
|
5
4
|
import { useTranslation } from '@digigov/ui/app/i18n';
|
|
5
|
+
import { FieldLabelProps } from '@digigov/form/types';
|
|
6
6
|
|
|
7
7
|
export interface FieldOptionProps {
|
|
8
8
|
label?: FieldLabelProps;
|
|
9
9
|
value: string;
|
|
10
|
+
show?: string[];
|
|
10
11
|
disabled?: boolean;
|
|
11
12
|
selected?: () => React.FC;
|
|
13
|
+
divider?: string;
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
export interface LabelProps {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import FormBuilder, { Field, Fieldset } from '@digigov/form';
|
|
3
|
-
import { FieldSpec } from '@digigov/form/types';
|
|
4
3
|
import { Button } from '@digigov/ui/core';
|
|
4
|
+
import { FieldSpec } from '@digigov/form/types';
|
|
5
5
|
const FIELDS: FieldSpec[] = [
|
|
6
6
|
{
|
|
7
7
|
key: 'otp',
|
|
@@ -52,6 +52,22 @@
|
|
|
52
52
|
"title": "select option with keyboard and submit"
|
|
53
53
|
}
|
|
54
54
|
]
|
|
55
|
+
},
|
|
56
|
+
"digigov-form-inputs-radio--conditional": {
|
|
57
|
+
"actionSets": [
|
|
58
|
+
{
|
|
59
|
+
"actions": [
|
|
60
|
+
{
|
|
61
|
+
"name": "click",
|
|
62
|
+
"args": {
|
|
63
|
+
"selector": "html>body>div:nth-child(5)>form>div>fieldset>div>div:nth-child(1)>div>label>input"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
"id": "LAUEuHh58XiI",
|
|
68
|
+
"title": "Radio conditional action"
|
|
69
|
+
}
|
|
70
|
+
]
|
|
55
71
|
}
|
|
56
72
|
}
|
|
57
73
|
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import FormBuilder, { Field, FieldSpec } from '@digigov/form';
|
|
3
|
+
import { Button } from '@digigov/ui/core';
|
|
4
|
+
|
|
5
|
+
const fields: FieldSpec[] = [
|
|
6
|
+
{
|
|
7
|
+
key: 'landline',
|
|
8
|
+
type: 'phone_number',
|
|
9
|
+
label: {
|
|
10
|
+
secondary: 'Εισάγετε το νούμερο του σταθερού σας τηλεφώνου.',
|
|
11
|
+
},
|
|
12
|
+
enabled: false,
|
|
13
|
+
condition: {
|
|
14
|
+
auth_form: {
|
|
15
|
+
is: 'via_mobile_phone',
|
|
16
|
+
then: {
|
|
17
|
+
enabled: true,
|
|
18
|
+
required: true,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
key: 'mobile_phone',
|
|
25
|
+
type: 'mobile_phone',
|
|
26
|
+
label: {
|
|
27
|
+
secondary: 'Εισάγετε το νούμερο του κινητού σας τηλεφώνου.',
|
|
28
|
+
},
|
|
29
|
+
enabled: false,
|
|
30
|
+
condition: {
|
|
31
|
+
auth_form: {
|
|
32
|
+
is: 'via_mobile_phone',
|
|
33
|
+
then: {
|
|
34
|
+
enabled: true,
|
|
35
|
+
required: true,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
key: 'email',
|
|
42
|
+
type: 'email',
|
|
43
|
+
label: {
|
|
44
|
+
secondary: 'Εισάγετε την διεύθυνση του ηλεκτρονικού σας ταχυδρομείου.',
|
|
45
|
+
},
|
|
46
|
+
enabled: false,
|
|
47
|
+
condition: {
|
|
48
|
+
auth_form: {
|
|
49
|
+
is: 'via_email',
|
|
50
|
+
then: {
|
|
51
|
+
enabled: true,
|
|
52
|
+
required: true,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
key: 'auth_form',
|
|
59
|
+
type: 'choice:single',
|
|
60
|
+
required:true,
|
|
61
|
+
label: {
|
|
62
|
+
primary: 'Επιλέξτε μέθοδο πιστοποίησης',
|
|
63
|
+
secondary:
|
|
64
|
+
'Για την ολοκλήρωση της δήλωσης σας, θα χρειαστεί επιπλέον πιστοποίηση. Θα σας στείλουμε ένα κωδικό μιας χρήσης είτε στο τηλέφωνο είτε στην ηλεκτρονική σας διεύθυνση.',
|
|
65
|
+
},
|
|
66
|
+
extra: {
|
|
67
|
+
options: [
|
|
68
|
+
{
|
|
69
|
+
key: 'via_mobile_phone',
|
|
70
|
+
label: { primary: 'Mέσω κινητού τηλεφώνου' },
|
|
71
|
+
value: 'via_mobile_phone',
|
|
72
|
+
show: ['mobile_phone', 'landline'],
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
key: 'via_email',
|
|
76
|
+
label: {
|
|
77
|
+
primary: 'Μέσω διεύθυνσης ηλεκτρονικού ταχυδρομείου (e-mail)',
|
|
78
|
+
},
|
|
79
|
+
value: 'via_email',
|
|
80
|
+
show: ['email'],
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
export const Conditional = () => (
|
|
88
|
+
<FormBuilder
|
|
89
|
+
onSubmit={(data) => {
|
|
90
|
+
console.log(data);
|
|
91
|
+
}}
|
|
92
|
+
fields={fields}
|
|
93
|
+
>
|
|
94
|
+
<Field key="auth_form" name="auth_form" />
|
|
95
|
+
<Button type="submit">Συνέχεια</Button>
|
|
96
|
+
</FormBuilder>
|
|
97
|
+
);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import FormBuilder, { Field } from '@digigov/form';
|
|
3
|
+
import { Button } from '@digigov/ui/core';
|
|
4
|
+
|
|
5
|
+
export const WithDivider = () => (
|
|
6
|
+
<FormBuilder
|
|
7
|
+
onSubmit={(data) => {
|
|
8
|
+
console.log(data);
|
|
9
|
+
}}
|
|
10
|
+
>
|
|
11
|
+
<Field
|
|
12
|
+
key={'string'}
|
|
13
|
+
name="string"
|
|
14
|
+
type="choice:single"
|
|
15
|
+
required
|
|
16
|
+
label={{ primary: 'Ποια ειναι η χώρα της διαμονής σας;' }}
|
|
17
|
+
extra={{
|
|
18
|
+
options: [
|
|
19
|
+
{
|
|
20
|
+
label: { primary: 'Ελλάδα' },
|
|
21
|
+
value: 'greece',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
label: { primary: 'Κύπρος' },
|
|
25
|
+
value: 'cyprus',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
label: { primary: 'Χώρα της Ευρωπαϊκής Ένωσης' },
|
|
29
|
+
value: 'eu',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
label: { primary: 'Ηνωμένες Πολιτείες της Αμερικής' },
|
|
33
|
+
value: 'usa',
|
|
34
|
+
divider:'ή'
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
}}
|
|
38
|
+
/>
|
|
39
|
+
<Button type="submit">Συνέχεια</Button>
|
|
40
|
+
</FormBuilder>
|
|
41
|
+
);
|
|
42
|
+
export default WithDivider;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { useWatch } from 'react-hook-form';
|
|
3
|
-
import { UncontrolledFieldProps } from '@digigov/form/Field/types';
|
|
4
|
-
import { FieldOptionProps } from '@digigov/form/inputs/Label';
|
|
5
|
-
import Hint from '@digigov/react-core/Hint';
|
|
6
2
|
import RadioContainer from '@digigov/react-core/RadioContainer';
|
|
7
3
|
import RadioItem from '@digigov/react-core/RadioItem';
|
|
8
4
|
import { useTranslation } from '@digigov/ui/app/i18n';
|
|
5
|
+
import { FieldOptionProps } from '@digigov/form/inputs/Label';
|
|
6
|
+
import { UncontrolledFieldProps } from '@digigov/form/Field/types';
|
|
7
|
+
import { useWatch } from 'react-hook-form';
|
|
8
|
+
import Hint from '@digigov/react-core/Hint';
|
|
9
|
+
import { Field } from '@digigov/form';
|
|
10
|
+
import { RadioConditional } from '@digigov/react-core';
|
|
9
11
|
|
|
10
12
|
export interface RadioButtonsGroupProps
|
|
11
13
|
extends Omit<UncontrolledFieldProps, 'extra'> {
|
|
@@ -29,12 +31,20 @@ export const RadioButtonsGroup: React.FC<RadioButtonsGroupProps> = ({
|
|
|
29
31
|
return (
|
|
30
32
|
<RadioContainer className={className} defaultValue={currentValue} id={name}>
|
|
31
33
|
{options.map(
|
|
32
|
-
({
|
|
34
|
+
({
|
|
35
|
+
label,
|
|
36
|
+
value: v,
|
|
37
|
+
show,
|
|
38
|
+
disabled: optionDisabled,
|
|
39
|
+
selected,
|
|
40
|
+
...option
|
|
41
|
+
}) => (
|
|
33
42
|
<div key={`${name}.${v}`}>
|
|
34
43
|
<RadioItem
|
|
35
44
|
{...register(name)}
|
|
36
45
|
value={v}
|
|
37
46
|
disabled={disabled || optionDisabled}
|
|
47
|
+
{...option}
|
|
38
48
|
{...{
|
|
39
49
|
...props,
|
|
40
50
|
reset: undefined,
|
|
@@ -47,6 +57,13 @@ export const RadioButtonsGroup: React.FC<RadioButtonsGroupProps> = ({
|
|
|
47
57
|
{label && label.secondary && <Hint>{t(label.secondary)}</Hint>}
|
|
48
58
|
</RadioItem>
|
|
49
59
|
{selected && selected()}
|
|
60
|
+
{currentValue === v && show && (
|
|
61
|
+
<RadioConditional>
|
|
62
|
+
{show.map((fieldName) => (
|
|
63
|
+
<Field name={fieldName} key={fieldName} />
|
|
64
|
+
))}
|
|
65
|
+
</RadioConditional>
|
|
66
|
+
)}
|
|
50
67
|
</div>
|
|
51
68
|
)
|
|
52
69
|
)}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { UncontrolledFieldProps } from '@digigov/form/Field/types';
|
|
3
|
-
import { FieldOptionProps } from '@digigov/form/inputs/Label';
|
|
4
2
|
import SelectContainer from '@digigov/react-core/SelectContainer';
|
|
5
3
|
import SelectOption from '@digigov/react-core/SelectOption';
|
|
4
|
+
import { FieldOptionProps } from '@digigov/form/inputs/Label';
|
|
5
|
+
import { UncontrolledFieldProps } from '@digigov/form/Field/types';
|
|
6
6
|
|
|
7
7
|
export interface SelectProps extends Omit<UncontrolledFieldProps, 'extra'> {
|
|
8
8
|
extra: {
|
package/src/registry.js
CHANGED
|
@@ -56,8 +56,10 @@ import * as _digigov_form_validators_utils_number from '@digigov/form/validators
|
|
|
56
56
|
import * as _digigov_form_validators_utils_otp from '@digigov/form/validators/utils/otp';
|
|
57
57
|
import * as _digigov_form_validators_utils_phone from '@digigov/form/validators/utils/phone';
|
|
58
58
|
import * as _digigov_form_validators_utils_postal_code from '@digigov/form/validators/utils/postal_code';
|
|
59
|
+
import * as _digigov_form_validators_utils_text_limit from '@digigov/form/validators/utils/text_limit';
|
|
59
60
|
import * as _digigov_form_validators_utils_uuid4 from '@digigov/form/validators/utils/uuid4'
|
|
60
61
|
function lazyImport(pkgImport) {
|
|
62
|
+
// eslint-disable-next-line no-undef
|
|
61
63
|
return new Proxy(
|
|
62
64
|
{},
|
|
63
65
|
{
|
|
@@ -133,6 +135,7 @@ export default {
|
|
|
133
135
|
'@digigov/form/validators/utils/otp': lazyImport(_digigov_form_validators_utils_otp),
|
|
134
136
|
'@digigov/form/validators/utils/phone': lazyImport(_digigov_form_validators_utils_phone),
|
|
135
137
|
'@digigov/form/validators/utils/postal_code': lazyImport(_digigov_form_validators_utils_postal_code),
|
|
138
|
+
'@digigov/form/validators/utils/text_limit': lazyImport(_digigov_form_validators_utils_text_limit),
|
|
136
139
|
'@digigov/form/validators/utils/uuid4': lazyImport(_digigov_form_validators_utils_uuid4)
|
|
137
140
|
};
|
|
138
141
|
|
package/src/types.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { UseFormReturn, UseFormProps } from 'react-hook-form';
|
|
2
|
-
import { FieldComponentRegistry } from '@digigov/form/Field/types';
|
|
3
|
-
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
4
2
|
import { GridProps } from '@digigov/ui/layouts/Grid';
|
|
3
|
+
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
4
|
+
import { FieldComponentRegistry } from '@digigov/form/Field/types';
|
|
5
5
|
|
|
6
6
|
export type FieldError = {
|
|
7
7
|
message: string;
|
|
@@ -13,7 +13,7 @@ export type FieldLabelProps = {
|
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
export interface FieldCondition {
|
|
16
|
-
is: string;
|
|
16
|
+
is: string | string[] | number | number[] | boolean | boolean[];
|
|
17
17
|
then?: Partial<FieldSpec>;
|
|
18
18
|
else?: Partial<FieldSpec>;
|
|
19
19
|
}
|
|
@@ -43,7 +43,9 @@ export interface FieldSpec {
|
|
|
43
43
|
condition?: Record<string, FieldCondition>;
|
|
44
44
|
controlled?: boolean;
|
|
45
45
|
label?: FieldLabelProps;
|
|
46
|
-
extra?:
|
|
46
|
+
extra?: {
|
|
47
|
+
[key: string]: any;
|
|
48
|
+
};
|
|
47
49
|
editable?: boolean;
|
|
48
50
|
required?: boolean;
|
|
49
51
|
enabled?: boolean;
|
package/src/utils.ts
CHANGED
package/src/validators/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
OTP_VALIDATOR,
|
|
13
13
|
MOBILE_PHONE_VALIDATOR,
|
|
14
14
|
PHONE_NUMBER_VALIDATOR,
|
|
15
|
+
TEXT_LIMIT_VALIDATOR,
|
|
15
16
|
POSTALCODE_VALIDATOR,
|
|
16
17
|
UUID4_VALIDATOR,
|
|
17
18
|
} from '@digigov/form/validators/utils';
|
|
@@ -46,7 +47,6 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
46
47
|
.test(FILE_MAX_SIZE_VALIDATOR(field));
|
|
47
48
|
},
|
|
48
49
|
string: yup.string,
|
|
49
|
-
text: yup.string,
|
|
50
50
|
boolean: yup.boolean,
|
|
51
51
|
object: (
|
|
52
52
|
field
|
|
@@ -107,6 +107,13 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
107
107
|
uuid4: (): yup.StringSchema => yup.string().test(UUID4_VALIDATOR),
|
|
108
108
|
iban: (field): yup.StringSchema => yup.string().test(IBAN_VALIDATOR(field)),
|
|
109
109
|
otp: (field): yup.StringSchema => yup.string().test(OTP_VALIDATOR(field)),
|
|
110
|
+
text: (field): yup.StringSchema => {
|
|
111
|
+
if (field?.extra?.limit?.max || !!field?.extra?.limit?.min) {
|
|
112
|
+
return yup.string().test(TEXT_LIMIT_VALIDATOR(field));
|
|
113
|
+
} else {
|
|
114
|
+
return yup.string();
|
|
115
|
+
}
|
|
116
|
+
},
|
|
110
117
|
postal_code: (field): yup.StringSchema =>
|
|
111
118
|
yup.string().test(POSTALCODE_VALIDATOR(field)),
|
|
112
119
|
mobile_phone: (): yup.StringSchema =>
|
|
@@ -9,6 +9,7 @@ export * from '@digigov/form/validators/utils/otp';
|
|
|
9
9
|
export * from '@digigov/form/validators/utils/phone';
|
|
10
10
|
export * from '@digigov/form/validators/utils/postal_code';
|
|
11
11
|
export * from '@digigov/form/validators/utils/uuid4';
|
|
12
|
+
export * from '@digigov/form/validators/utils/text_limit';
|
|
12
13
|
|
|
13
14
|
export function getYupField(field: FieldSpec, yupTypeMap: Record<string, any>) {
|
|
14
15
|
const yupField = yupTypeMap[field?.type || 'string'] || yupTypeMap['string'];
|
|
@@ -42,7 +43,15 @@ export function computeShape(
|
|
|
42
43
|
}
|
|
43
44
|
if (then || otherwise) {
|
|
44
45
|
yupField = yupField.when(key, {
|
|
45
|
-
is:
|
|
46
|
+
is: (val) => {
|
|
47
|
+
//@ts-ignore
|
|
48
|
+
const is = field.condition[key].is;
|
|
49
|
+
if (is === val || (Array.isArray(val) && val.includes(is))) {
|
|
50
|
+
return true;
|
|
51
|
+
} else {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
},
|
|
46
55
|
then,
|
|
47
56
|
otherwise,
|
|
48
57
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as gPhoneNumber from 'google-libphonenumber';
|
|
2
|
-
import { FieldSpec } from '@digigov/form/types';
|
|
3
2
|
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
3
|
+
import { FieldSpec } from '@digigov/form/types';
|
|
4
4
|
|
|
5
5
|
export type PhoneNumberType = 'landline' | 'mobile' | null;
|
|
6
6
|
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { FieldSpec } from '@digigov/form/types';
|
|
2
|
+
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
3
|
+
|
|
4
|
+
export function validateText(value: string, min: number, max: number): boolean {
|
|
5
|
+
let validator;
|
|
6
|
+
if (min || max) {
|
|
7
|
+
if (value.length < min || value.length > max) {
|
|
8
|
+
return (validator = false);
|
|
9
|
+
} else {
|
|
10
|
+
return (validator = true);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return validator;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const TEXT_LIMIT_VALIDATOR = (field: FieldSpec): ValidatorSchema => {
|
|
17
|
+
const min: number = field?.extra?.limit?.min;
|
|
18
|
+
const max: number = field?.extra?.limit?.max;
|
|
19
|
+
return {
|
|
20
|
+
name: 'text-limit-validator',
|
|
21
|
+
message: (v: any): any => {
|
|
22
|
+
if (min || max) {
|
|
23
|
+
if (v.value.length < min) {
|
|
24
|
+
return {
|
|
25
|
+
key: 'form.error.text.less_than',
|
|
26
|
+
context: { min: field?.extra?.limit?.min },
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
if (v.value.length > max) {
|
|
30
|
+
return {
|
|
31
|
+
key: 'form.error.text.more_than',
|
|
32
|
+
context: { max: field?.extra?.limit?.max },
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
test: (value: string): boolean => {
|
|
38
|
+
if (!value) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
return validateText(value, min as number, max as number);
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
};
|
package/types.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { UseFormReturn, UseFormProps } from 'react-hook-form';
|
|
3
|
-
import { FieldComponentRegistry } from '@digigov/form/Field/types';
|
|
4
|
-
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
5
3
|
import { GridProps } from '@digigov/ui/layouts/Grid';
|
|
4
|
+
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
5
|
+
import { FieldComponentRegistry } from '@digigov/form/Field/types';
|
|
6
6
|
export declare type FieldError = {
|
|
7
7
|
message: string;
|
|
8
8
|
};
|
|
@@ -11,7 +11,7 @@ export declare type FieldLabelProps = {
|
|
|
11
11
|
secondary?: string;
|
|
12
12
|
};
|
|
13
13
|
export interface FieldCondition {
|
|
14
|
-
is: string;
|
|
14
|
+
is: string | string[] | number | number[] | boolean | boolean[];
|
|
15
15
|
then?: Partial<FieldSpec>;
|
|
16
16
|
else?: Partial<FieldSpec>;
|
|
17
17
|
}
|
|
@@ -23,7 +23,9 @@ export interface FieldSpec {
|
|
|
23
23
|
condition?: Record<string, FieldCondition>;
|
|
24
24
|
controlled?: boolean;
|
|
25
25
|
label?: FieldLabelProps;
|
|
26
|
-
extra?:
|
|
26
|
+
extra?: {
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
};
|
|
27
29
|
editable?: boolean;
|
|
28
30
|
required?: boolean;
|
|
29
31
|
enabled?: boolean;
|
package/validators/index.js
CHANGED
|
@@ -51,7 +51,6 @@ var getYUPTypeMap = function getYUPTypeMap() {
|
|
|
51
51
|
}).nullable().test((0, _utils.FILE_MAX_SIZE_VALIDATOR)(field));
|
|
52
52
|
},
|
|
53
53
|
string: yup.string,
|
|
54
|
-
text: yup.string,
|
|
55
54
|
"boolean": yup["boolean"],
|
|
56
55
|
object: function object(field) {
|
|
57
56
|
return (0, _utils.getYupObjectShape)(field.extra.fields, yupTypeMap);
|
|
@@ -107,6 +106,15 @@ var getYUPTypeMap = function getYUPTypeMap() {
|
|
|
107
106
|
otp: function otp(field) {
|
|
108
107
|
return yup.string().test((0, _utils.OTP_VALIDATOR)(field));
|
|
109
108
|
},
|
|
109
|
+
text: function text(field) {
|
|
110
|
+
var _field$extra, _field$extra$limit, _field$extra2, _field$extra2$limit;
|
|
111
|
+
|
|
112
|
+
if (field !== null && field !== void 0 && (_field$extra = field.extra) !== null && _field$extra !== void 0 && (_field$extra$limit = _field$extra.limit) !== null && _field$extra$limit !== void 0 && _field$extra$limit.max || !!(field !== null && field !== void 0 && (_field$extra2 = field.extra) !== null && _field$extra2 !== void 0 && (_field$extra2$limit = _field$extra2.limit) !== null && _field$extra2$limit !== void 0 && _field$extra2$limit.min)) {
|
|
113
|
+
return yup.string().test((0, _utils.TEXT_LIMIT_VALIDATOR)(field));
|
|
114
|
+
} else {
|
|
115
|
+
return yup.string();
|
|
116
|
+
}
|
|
117
|
+
},
|
|
110
118
|
postal_code: function postal_code(field) {
|
|
111
119
|
return yup.string().test((0, _utils.POSTALCODE_VALIDATOR)(field));
|
|
112
120
|
},
|
|
@@ -8,6 +8,7 @@ export * from '@digigov/form/validators/utils/otp';
|
|
|
8
8
|
export * from '@digigov/form/validators/utils/phone';
|
|
9
9
|
export * from '@digigov/form/validators/utils/postal_code';
|
|
10
10
|
export * from '@digigov/form/validators/utils/uuid4';
|
|
11
|
+
export * from '@digigov/form/validators/utils/text_limit';
|
|
11
12
|
export declare function getYupField(field: FieldSpec, yupTypeMap: Record<string, any>): any;
|
|
12
13
|
export declare function computeShape(fields: FieldSpec[], yupTypeMap: Record<string, ValidatorSchema>, validatorRegistry: Record<string, ValidatorSchema[]> | undefined): {};
|
|
13
14
|
export declare function getYupObjectShape(fields: FieldSpec[] | any, yupTypeMap: Record<string, any>, validatorRegistry?: Record<string, ValidatorSchema[]>): yup.ObjectSchema<{
|