@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,11 +1,15 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
-
var _excluded = ["name", "onChange", "value", "extra", "disabled"]
|
|
4
|
-
|
|
4
|
+
var _excluded = ["name", "onChange", "value", "extra", "disabled"],
|
|
5
|
+
_excluded2 = ["label", "value", "show", "disabled", "selected"];
|
|
6
|
+
import React, { useState } from 'react';
|
|
7
|
+
import { useTranslation } from '@digigov/ui/app/i18n';
|
|
5
8
|
import CoreCheckboxes from '@digigov/react-core/Checkbox';
|
|
6
9
|
import CheckboxItem from '@digigov/react-core/CheckboxItem';
|
|
7
10
|
import Hint from '@digigov/react-core/Hint';
|
|
8
|
-
import {
|
|
11
|
+
import { Field } from '@digigov/form';
|
|
12
|
+
import { CheckboxConditional } from '@digigov/react-core';
|
|
9
13
|
export var Checkboxes = function Checkboxes(_ref) {
|
|
10
14
|
var name = _ref.name,
|
|
11
15
|
onChange = _ref.onChange,
|
|
@@ -18,7 +22,7 @@ export var Checkboxes = function Checkboxes(_ref) {
|
|
|
18
22
|
|
|
19
23
|
if (!value) value = [];
|
|
20
24
|
|
|
21
|
-
var handleChange = function handleChange(optionValue) {
|
|
25
|
+
var handleChange = function handleChange(optionValue, idx, show) {
|
|
22
26
|
return function (evt) {
|
|
23
27
|
var newValue;
|
|
24
28
|
|
|
@@ -32,6 +36,14 @@ export var Checkboxes = function Checkboxes(_ref) {
|
|
|
32
36
|
newValue = value.filter(function (val) {
|
|
33
37
|
return val !== optionValue;
|
|
34
38
|
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (show && show.length > 0) {
|
|
42
|
+
setChecked(function (items) {
|
|
43
|
+
return items.map(function (item, index) {
|
|
44
|
+
return index === idx ? !item : item;
|
|
45
|
+
});
|
|
46
|
+
});
|
|
35
47
|
} // reset value to undefined instead of an empty array
|
|
36
48
|
// so the error state mechanism can throw validation errors
|
|
37
49
|
|
|
@@ -44,17 +56,32 @@ export var Checkboxes = function Checkboxes(_ref) {
|
|
|
44
56
|
var _useTranslation = useTranslation(),
|
|
45
57
|
t = _useTranslation.t;
|
|
46
58
|
|
|
59
|
+
var _useState = useState(Array(options.length).fill(false)),
|
|
60
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
61
|
+
checked = _useState2[0],
|
|
62
|
+
setChecked = _useState2[1];
|
|
63
|
+
|
|
47
64
|
return /*#__PURE__*/React.createElement(CoreCheckboxes, {
|
|
48
65
|
className: className
|
|
49
|
-
}, options.map(function (
|
|
50
|
-
|
|
66
|
+
}, options.map(function (_ref2, index) {
|
|
67
|
+
var _value;
|
|
68
|
+
|
|
69
|
+
var label = _ref2.label,
|
|
70
|
+
v = _ref2.value,
|
|
71
|
+
show = _ref2.show,
|
|
72
|
+
optionDisabled = _ref2.disabled,
|
|
73
|
+
selected = _ref2.selected,
|
|
74
|
+
option = _objectWithoutProperties(_ref2, _excluded2);
|
|
75
|
+
|
|
76
|
+
return /*#__PURE__*/React.createElement(React.Fragment, {
|
|
77
|
+
key: index
|
|
78
|
+
}, /*#__PURE__*/React.createElement(CheckboxItem, _extends({
|
|
79
|
+
key: "".concat(name, ".").concat(index),
|
|
51
80
|
name: name,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
,
|
|
56
|
-
checked: value.includes(option.value),
|
|
57
|
-
onChange: handleChange(option.value)
|
|
81
|
+
value: v,
|
|
82
|
+
disabled: disabled || optionDisabled,
|
|
83
|
+
checked: (_value = value) === null || _value === void 0 ? void 0 : _value.includes(v),
|
|
84
|
+
onChange: handleChange(v, index, show)
|
|
58
85
|
}, option, _extends({}, props, {
|
|
59
86
|
reset: undefined,
|
|
60
87
|
defaultValue: undefined,
|
|
@@ -62,7 +89,12 @@ export var Checkboxes = function Checkboxes(_ref) {
|
|
|
62
89
|
required: undefined,
|
|
63
90
|
'aria-describedby': undefined,
|
|
64
91
|
type: 'checkbox'
|
|
65
|
-
})),
|
|
92
|
+
})), label && label.primary && t(label.primary) || value, label && label.secondary && /*#__PURE__*/React.createElement(Hint, null, t(label.secondary))), !!checked[index] && show && /*#__PURE__*/React.createElement(CheckboxConditional, null, show.map(function (fieldName) {
|
|
93
|
+
return /*#__PURE__*/React.createElement(Field, {
|
|
94
|
+
name: fieldName,
|
|
95
|
+
key: fieldName
|
|
96
|
+
});
|
|
97
|
+
})), selected && selected());
|
|
66
98
|
}));
|
|
67
99
|
};
|
|
68
100
|
export default Checkboxes;
|
|
@@ -5,9 +5,9 @@ var _excluded = ["label"],
|
|
|
5
5
|
import React, { useMemo, useState } from 'react';
|
|
6
6
|
import dayjs from 'dayjs';
|
|
7
7
|
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
8
|
+
import { useTranslation } from '@digigov/ui/app/i18n';
|
|
8
9
|
import DateInputContainer from '@digigov/react-core/DateInputContainer';
|
|
9
10
|
import CoreDateInputItem from '@digigov/react-core/DateInputItem';
|
|
10
|
-
import { useTranslation } from '@digigov/ui/app/i18n';
|
|
11
11
|
dayjs.extend(customParseFormat);
|
|
12
12
|
|
|
13
13
|
function useDate(value, onChange) {
|
|
@@ -4,12 +4,12 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
|
4
4
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
5
5
|
var _excluded = ["name", "extra", "disabled", "reset", "onChange"];
|
|
6
6
|
import React, { useState } from 'react';
|
|
7
|
-
import FileUpload from '@digigov/react-core/FileUpload';
|
|
8
|
-
import FileUploadContainer from '@digigov/react-core/FileUploadContainer';
|
|
9
|
-
import CoreHint from '@digigov/react-core/Hint';
|
|
10
7
|
import { useTranslation } from '@digigov/ui/app/i18n';
|
|
11
|
-
import Button from '@digigov/ui/core/Button';
|
|
12
8
|
import Paragraph from '@digigov/ui/typography/Paragraph';
|
|
9
|
+
import CoreHint from '@digigov/react-core/Hint';
|
|
10
|
+
import Button from '@digigov/ui/core/Button';
|
|
11
|
+
import FileUploadContainer from '@digigov/react-core/FileUploadContainer';
|
|
12
|
+
import FileUpload from '@digigov/react-core/FileUpload';
|
|
13
13
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
14
|
export var FileInput = /*#__PURE__*/React.forwardRef(function FileInput(_ref, ref) {
|
|
15
15
|
var name = _ref.name,
|
|
@@ -11,4 +11,5 @@ export * from '@digigov/form/inputs/Input/__stories__/PhoneNumber';
|
|
|
11
11
|
export * from '@digigov/form/inputs/Input/__stories__/MobilePhone';
|
|
12
12
|
export * from '@digigov/form/inputs/Input/__stories__/AFM';
|
|
13
13
|
export * from '@digigov/form/inputs/Input/__stories__/IBAN';
|
|
14
|
-
export * from '@digigov/form/inputs/Input/__stories__/PostalCode';
|
|
14
|
+
export * from '@digigov/form/inputs/Input/__stories__/PostalCode';
|
|
15
|
+
export * from '@digigov/form/inputs/Input/__stories__/TextWithCharacterLimit';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import FormBuilder, { Field } from '@digigov/form';
|
|
3
|
+
import { Button } from '@digigov/ui/core';
|
|
4
|
+
|
|
5
|
+
var _ref = /*#__PURE__*/React.createElement(Button, {
|
|
6
|
+
type: "submit"
|
|
7
|
+
}, "\u03A3\u03C5\u03BD\u03AD\u03C7\u03B5\u03B9\u03B1");
|
|
8
|
+
|
|
9
|
+
export var TextWithCharacterLimit = function TextWithCharacterLimit() {
|
|
10
|
+
return /*#__PURE__*/React.createElement(FormBuilder, {
|
|
11
|
+
onSubmit: function onSubmit(data) {
|
|
12
|
+
console.log(data);
|
|
13
|
+
}
|
|
14
|
+
}, /*#__PURE__*/React.createElement(Field, {
|
|
15
|
+
key: "text",
|
|
16
|
+
name: "text",
|
|
17
|
+
type: "text",
|
|
18
|
+
label: {
|
|
19
|
+
primary: 'Μπορείτε να δώσετε περισσότερες πληροφορίες;'
|
|
20
|
+
},
|
|
21
|
+
required: true,
|
|
22
|
+
extra: {
|
|
23
|
+
limit: {
|
|
24
|
+
min: 3,
|
|
25
|
+
max: 10
|
|
26
|
+
},
|
|
27
|
+
multiline: true
|
|
28
|
+
}
|
|
29
|
+
}), _ref);
|
|
30
|
+
};
|
|
31
|
+
export default TextWithCharacterLimit;
|
package/es/inputs/Input/index.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
-
var _excluded = ["name", "type", "extra"];
|
|
3
|
+
var _excluded = ["name", "control", "type", "extra"];
|
|
4
4
|
import React from 'react';
|
|
5
|
-
import TextArea from '@digigov/react-core/TextArea';
|
|
6
5
|
import TextInput from '@digigov/react-core/TextInput';
|
|
6
|
+
import TextArea from '@digigov/react-core/TextArea';
|
|
7
|
+
import { Hint } from '@digigov/react-core';
|
|
8
|
+
import { useWatch } from 'react-hook-form';
|
|
9
|
+
import { useTranslation } from '@digigov/ui/app/i18n';
|
|
7
10
|
var TYPES_MAP = {
|
|
8
11
|
string: 'text',
|
|
9
12
|
"int": 'text',
|
|
@@ -12,14 +15,17 @@ var TYPES_MAP = {
|
|
|
12
15
|
};
|
|
13
16
|
export var Input = /*#__PURE__*/React.forwardRef(function WrappedInput(_ref, ref) {
|
|
14
17
|
var name = _ref.name,
|
|
18
|
+
control = _ref.control,
|
|
15
19
|
type = _ref.type,
|
|
16
20
|
extra = _ref.extra,
|
|
17
21
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
18
22
|
|
|
23
|
+
// eslint-disable-next-line prefer-const
|
|
19
24
|
var _ref2 = extra || {},
|
|
20
25
|
_ref2$multiline = _ref2.multiline,
|
|
21
26
|
multiline = _ref2$multiline === void 0 ? false : _ref2$multiline,
|
|
22
|
-
rows = _ref2.rows
|
|
27
|
+
rows = _ref2.rows,
|
|
28
|
+
limit = _ref2.limit;
|
|
23
29
|
|
|
24
30
|
var _ref3 = extra || {},
|
|
25
31
|
className = _ref3.className; // if enforced to multiline use true. Derive from type otherwise.
|
|
@@ -31,8 +37,16 @@ export var Input = /*#__PURE__*/React.forwardRef(function WrappedInput(_ref, ref
|
|
|
31
37
|
|
|
32
38
|
var fieldType = TYPES_MAP[type || 'text'] || 'text';
|
|
33
39
|
|
|
40
|
+
var _useTranslation = useTranslation(),
|
|
41
|
+
t = _useTranslation.t;
|
|
42
|
+
|
|
43
|
+
var currentValue = useWatch({
|
|
44
|
+
control: control,
|
|
45
|
+
name: name
|
|
46
|
+
});
|
|
47
|
+
|
|
34
48
|
if (multiline === true) {
|
|
35
|
-
return /*#__PURE__*/React.createElement(TextArea, _extends({
|
|
49
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(TextArea, _extends({
|
|
36
50
|
name: name,
|
|
37
51
|
className: className,
|
|
38
52
|
rows: rows,
|
|
@@ -41,7 +55,11 @@ export var Input = /*#__PURE__*/React.forwardRef(function WrappedInput(_ref, ref
|
|
|
41
55
|
reset: undefined,
|
|
42
56
|
required: undefined,
|
|
43
57
|
type: fieldType
|
|
44
|
-
})))
|
|
58
|
+
}))), (limit === null || limit === void 0 ? void 0 : limit.max) && /*#__PURE__*/React.createElement(Hint, null, currentValue === undefined || (currentValue === null || currentValue === void 0 ? void 0 : currentValue.length) >= 0 && (currentValue === null || currentValue === void 0 ? void 0 : currentValue.length) <= (limit === null || limit === void 0 ? void 0 : limit.max) ? /*#__PURE__*/React.createElement("span", null, t('form.info.text.you_have'), ' ', /*#__PURE__*/React.createElement("b", null, !currentValue ? limit.max : (limit === null || limit === void 0 ? void 0 : limit.max) - (currentValue === null || currentValue === void 0 ? void 0 : currentValue.length)), ' ', currentValue && (limit === null || limit === void 0 ? void 0 : limit.max) - (currentValue === null || currentValue === void 0 ? void 0 : currentValue.length) === 1 ? "".concat(t('form.info.text.character')) : "".concat(t('form.info.text.characters')), ' ', t('form.info.text.remaining'), ".") : /*#__PURE__*/React.createElement("span", {
|
|
59
|
+
style: {
|
|
60
|
+
color: '#b60202'
|
|
61
|
+
}
|
|
62
|
+
}, t('form.info.text.you_have'), ' ', /*#__PURE__*/React.createElement("b", null, currentValue && (currentValue === null || currentValue === void 0 ? void 0 : currentValue.length) - (limit === null || limit === void 0 ? void 0 : limit.max)), ' ', (currentValue === null || currentValue === void 0 ? void 0 : currentValue.length) - (limit === null || limit === void 0 ? void 0 : limit.max) === 1 ? "".concat(t('form.info.text.character')) : "".concat(t('form.info.text.characters')), ' ', t('form.info.text.too_many'), ".")));
|
|
45
63
|
} else {
|
|
46
64
|
return /*#__PURE__*/React.createElement(TextInput, _extends({
|
|
47
65
|
name: name,
|
package/es/inputs/Label/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import Hint from '@digigov/react-core/Hint';
|
|
3
2
|
import LabelTitle from '@digigov/react-core/LabelTitle';
|
|
3
|
+
import Hint from '@digigov/react-core/Hint';
|
|
4
4
|
import { useTranslation } from '@digigov/ui/app/i18n';
|
|
5
5
|
export var Label = function Label(_ref) {
|
|
6
6
|
var className = _ref.className,
|
|
@@ -4,4 +4,6 @@ export default {
|
|
|
4
4
|
component: Radio,
|
|
5
5
|
displayName: 'Radio'
|
|
6
6
|
};
|
|
7
|
-
export * from '@digigov/form/inputs/Radio/__stories__/Default';
|
|
7
|
+
export * from '@digigov/form/inputs/Radio/__stories__/Default';
|
|
8
|
+
export * from '@digigov/form/inputs/Radio/__stories__/WithDivider';
|
|
9
|
+
export * from '@digigov/form/inputs/Radio/__stories__/Conditional';
|
|
@@ -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,95 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import FormBuilder, { Field } from '@digigov/form';
|
|
3
|
+
import { Button } from '@digigov/ui/core';
|
|
4
|
+
var fields = [{
|
|
5
|
+
key: 'landline',
|
|
6
|
+
type: 'phone_number',
|
|
7
|
+
label: {
|
|
8
|
+
secondary: 'Εισάγετε το νούμερο του σταθερού σας τηλεφώνου.'
|
|
9
|
+
},
|
|
10
|
+
enabled: false,
|
|
11
|
+
condition: {
|
|
12
|
+
auth_form: {
|
|
13
|
+
is: 'via_mobile_phone',
|
|
14
|
+
then: {
|
|
15
|
+
enabled: true,
|
|
16
|
+
required: true
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}, {
|
|
21
|
+
key: 'mobile_phone',
|
|
22
|
+
type: 'mobile_phone',
|
|
23
|
+
label: {
|
|
24
|
+
secondary: 'Εισάγετε το νούμερο του κινητού σας τηλεφώνου.'
|
|
25
|
+
},
|
|
26
|
+
enabled: false,
|
|
27
|
+
condition: {
|
|
28
|
+
auth_form: {
|
|
29
|
+
is: 'via_mobile_phone',
|
|
30
|
+
then: {
|
|
31
|
+
enabled: true,
|
|
32
|
+
required: true
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}, {
|
|
37
|
+
key: 'email',
|
|
38
|
+
type: 'email',
|
|
39
|
+
label: {
|
|
40
|
+
secondary: 'Εισάγετε την διεύθυνση του ηλεκτρονικού σας ταχυδρομείου.'
|
|
41
|
+
},
|
|
42
|
+
enabled: false,
|
|
43
|
+
condition: {
|
|
44
|
+
auth_form: {
|
|
45
|
+
is: 'via_email',
|
|
46
|
+
then: {
|
|
47
|
+
enabled: true,
|
|
48
|
+
required: true
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}, {
|
|
53
|
+
key: 'auth_form',
|
|
54
|
+
type: 'choice:single',
|
|
55
|
+
required: true,
|
|
56
|
+
label: {
|
|
57
|
+
primary: 'Επιλέξτε μέθοδο πιστοποίησης',
|
|
58
|
+
secondary: 'Για την ολοκλήρωση της δήλωσης σας, θα χρειαστεί επιπλέον πιστοποίηση. Θα σας στείλουμε ένα κωδικό μιας χρήσης είτε στο τηλέφωνο είτε στην ηλεκτρονική σας διεύθυνση.'
|
|
59
|
+
},
|
|
60
|
+
extra: {
|
|
61
|
+
options: [{
|
|
62
|
+
key: 'via_mobile_phone',
|
|
63
|
+
label: {
|
|
64
|
+
primary: 'Mέσω κινητού τηλεφώνου'
|
|
65
|
+
},
|
|
66
|
+
value: 'via_mobile_phone',
|
|
67
|
+
show: ['mobile_phone', 'landline']
|
|
68
|
+
}, {
|
|
69
|
+
key: 'via_email',
|
|
70
|
+
label: {
|
|
71
|
+
primary: 'Μέσω διεύθυνσης ηλεκτρονικού ταχυδρομείου (e-mail)'
|
|
72
|
+
},
|
|
73
|
+
value: 'via_email',
|
|
74
|
+
show: ['email']
|
|
75
|
+
}]
|
|
76
|
+
}
|
|
77
|
+
}];
|
|
78
|
+
|
|
79
|
+
var _ref = /*#__PURE__*/React.createElement(Field, {
|
|
80
|
+
key: "auth_form",
|
|
81
|
+
name: "auth_form"
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
var _ref2 = /*#__PURE__*/React.createElement(Button, {
|
|
85
|
+
type: "submit"
|
|
86
|
+
}, "\u03A3\u03C5\u03BD\u03AD\u03C7\u03B5\u03B9\u03B1");
|
|
87
|
+
|
|
88
|
+
export var Conditional = function Conditional() {
|
|
89
|
+
return /*#__PURE__*/React.createElement(FormBuilder, {
|
|
90
|
+
onSubmit: function onSubmit(data) {
|
|
91
|
+
console.log(data);
|
|
92
|
+
},
|
|
93
|
+
fields: fields
|
|
94
|
+
}, _ref, _ref2);
|
|
95
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import FormBuilder, { Field } from '@digigov/form';
|
|
3
|
+
import { Button } from '@digigov/ui/core';
|
|
4
|
+
|
|
5
|
+
var _ref = /*#__PURE__*/React.createElement(Button, {
|
|
6
|
+
type: "submit"
|
|
7
|
+
}, "\u03A3\u03C5\u03BD\u03AD\u03C7\u03B5\u03B9\u03B1");
|
|
8
|
+
|
|
9
|
+
export var WithDivider = function WithDivider() {
|
|
10
|
+
return /*#__PURE__*/React.createElement(FormBuilder, {
|
|
11
|
+
onSubmit: function onSubmit(data) {
|
|
12
|
+
console.log(data);
|
|
13
|
+
}
|
|
14
|
+
}, /*#__PURE__*/React.createElement(Field, {
|
|
15
|
+
key: 'string',
|
|
16
|
+
name: "string",
|
|
17
|
+
type: "choice:single",
|
|
18
|
+
required: true,
|
|
19
|
+
label: {
|
|
20
|
+
primary: 'Ποια ειναι η χώρα της διαμονής σας;'
|
|
21
|
+
},
|
|
22
|
+
extra: {
|
|
23
|
+
options: [{
|
|
24
|
+
label: {
|
|
25
|
+
primary: 'Ελλάδα'
|
|
26
|
+
},
|
|
27
|
+
value: 'greece'
|
|
28
|
+
}, {
|
|
29
|
+
label: {
|
|
30
|
+
primary: 'Κύπρος'
|
|
31
|
+
},
|
|
32
|
+
value: 'cyprus'
|
|
33
|
+
}, {
|
|
34
|
+
label: {
|
|
35
|
+
primary: 'Χώρα της Ευρωπαϊκής Ένωσης'
|
|
36
|
+
},
|
|
37
|
+
value: 'eu'
|
|
38
|
+
}, {
|
|
39
|
+
label: {
|
|
40
|
+
primary: 'Ηνωμένες Πολιτείες της Αμερικής'
|
|
41
|
+
},
|
|
42
|
+
value: 'usa',
|
|
43
|
+
divider: 'ή'
|
|
44
|
+
}]
|
|
45
|
+
}
|
|
46
|
+
}), _ref);
|
|
47
|
+
};
|
|
48
|
+
export default WithDivider;
|
package/es/inputs/Radio/index.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
-
var _excluded = ["name", "control", "register", "extra", "disabled"]
|
|
3
|
+
var _excluded = ["name", "control", "register", "extra", "disabled"],
|
|
4
|
+
_excluded2 = ["label", "value", "show", "disabled", "selected"];
|
|
4
5
|
import React from 'react';
|
|
5
|
-
import { useWatch } from 'react-hook-form';
|
|
6
|
-
import Hint from '@digigov/react-core/Hint';
|
|
7
6
|
import RadioContainer from '@digigov/react-core/RadioContainer';
|
|
8
7
|
import RadioItem from '@digigov/react-core/RadioItem';
|
|
9
8
|
import { useTranslation } from '@digigov/ui/app/i18n';
|
|
9
|
+
import { useWatch } from 'react-hook-form';
|
|
10
|
+
import Hint from '@digigov/react-core/Hint';
|
|
11
|
+
import { Field } from '@digigov/form';
|
|
12
|
+
import { RadioConditional } from '@digigov/react-core';
|
|
10
13
|
export var RadioButtonsGroup = function RadioButtonsGroup(_ref) {
|
|
11
14
|
var name = _ref.name,
|
|
12
15
|
control = _ref.control,
|
|
@@ -32,19 +35,27 @@ export var RadioButtonsGroup = function RadioButtonsGroup(_ref) {
|
|
|
32
35
|
}, options.map(function (_ref2) {
|
|
33
36
|
var label = _ref2.label,
|
|
34
37
|
v = _ref2.value,
|
|
38
|
+
show = _ref2.show,
|
|
35
39
|
optionDisabled = _ref2.disabled,
|
|
36
|
-
selected = _ref2.selected
|
|
40
|
+
selected = _ref2.selected,
|
|
41
|
+
option = _objectWithoutProperties(_ref2, _excluded2);
|
|
42
|
+
|
|
37
43
|
return /*#__PURE__*/React.createElement("div", {
|
|
38
44
|
key: "".concat(name, ".").concat(v)
|
|
39
45
|
}, /*#__PURE__*/React.createElement(RadioItem, _extends({}, register(name), {
|
|
40
46
|
value: v,
|
|
41
47
|
disabled: disabled || optionDisabled
|
|
42
|
-
}, _extends({}, props, {
|
|
48
|
+
}, option, _extends({}, props, {
|
|
43
49
|
reset: undefined,
|
|
44
50
|
required: undefined,
|
|
45
51
|
'aria-describedby': undefined,
|
|
46
52
|
type: 'radio'
|
|
47
|
-
})), label && label.primary && t(label.primary) || v, label && label.secondary && /*#__PURE__*/React.createElement(Hint, null, t(label.secondary))), selected && selected())
|
|
53
|
+
})), label && label.primary && t(label.primary) || v, label && label.secondary && /*#__PURE__*/React.createElement(Hint, null, t(label.secondary))), selected && selected(), currentValue === v && show && /*#__PURE__*/React.createElement(RadioConditional, null, show.map(function (fieldName) {
|
|
54
|
+
return /*#__PURE__*/React.createElement(Field, {
|
|
55
|
+
name: fieldName,
|
|
56
|
+
key: fieldName
|
|
57
|
+
});
|
|
58
|
+
})));
|
|
48
59
|
}));
|
|
49
60
|
};
|
|
50
61
|
export default RadioButtonsGroup;
|
package/es/registry.js
CHANGED
|
@@ -55,9 +55,11 @@ import * as _digigov_form_validators_utils_number from '@digigov/form/validators
|
|
|
55
55
|
import * as _digigov_form_validators_utils_otp from '@digigov/form/validators/utils/otp';
|
|
56
56
|
import * as _digigov_form_validators_utils_phone from '@digigov/form/validators/utils/phone';
|
|
57
57
|
import * as _digigov_form_validators_utils_postal_code from '@digigov/form/validators/utils/postal_code';
|
|
58
|
+
import * as _digigov_form_validators_utils_text_limit from '@digigov/form/validators/utils/text_limit';
|
|
58
59
|
import * as _digigov_form_validators_utils_uuid4 from '@digigov/form/validators/utils/uuid4';
|
|
59
60
|
|
|
60
61
|
function lazyImport(pkgImport) {
|
|
62
|
+
// eslint-disable-next-line no-undef
|
|
61
63
|
return new Proxy({}, {
|
|
62
64
|
get: function get(_target, name) {
|
|
63
65
|
if (name === '__esModule' || name === 'default') {
|
|
@@ -129,5 +131,6 @@ export default {
|
|
|
129
131
|
'@digigov/form/validators/utils/otp': lazyImport(_digigov_form_validators_utils_otp),
|
|
130
132
|
'@digigov/form/validators/utils/phone': lazyImport(_digigov_form_validators_utils_phone),
|
|
131
133
|
'@digigov/form/validators/utils/postal_code': lazyImport(_digigov_form_validators_utils_postal_code),
|
|
134
|
+
'@digigov/form/validators/utils/text_limit': lazyImport(_digigov_form_validators_utils_text_limit),
|
|
132
135
|
'@digigov/form/validators/utils/uuid4': lazyImport(_digigov_form_validators_utils_uuid4)
|
|
133
136
|
};
|
package/es/utils.js
CHANGED
|
@@ -6,11 +6,11 @@ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyri
|
|
|
6
6
|
|
|
7
7
|
import { validateFieldsNatively } from '@hookform/resolvers';
|
|
8
8
|
import { appendErrors } from 'react-hook-form';
|
|
9
|
-
|
|
10
9
|
/**
|
|
11
10
|
* Why `path!` ? because it could be `undefined` in some case
|
|
12
11
|
* https://github.com/jquense/yup#validationerrorerrors-string--arraystring-value-any-path-string
|
|
13
12
|
*/
|
|
13
|
+
|
|
14
14
|
var parseErrorSchema = function parseErrorSchema(error, validateAllFieldCriteria) {
|
|
15
15
|
return (error.inner || []).reduce(function (previous, error) {
|
|
16
16
|
var _error$path;
|
package/es/validators/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import * as yup from 'yup';
|
|
|
3
3
|
import { useMemo } from 'react';
|
|
4
4
|
import dayjs from 'dayjs';
|
|
5
5
|
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
6
|
-
import { getYupObjectShape, AFM_VALIDATOR, FILE_MAX_SIZE_VALIDATOR, IBAN_VALIDATOR, OTP_VALIDATOR, MOBILE_PHONE_VALIDATOR, PHONE_NUMBER_VALIDATOR, POSTALCODE_VALIDATOR, UUID4_VALIDATOR } from '@digigov/form/validators/utils';
|
|
6
|
+
import { getYupObjectShape, AFM_VALIDATOR, FILE_MAX_SIZE_VALIDATOR, IBAN_VALIDATOR, OTP_VALIDATOR, MOBILE_PHONE_VALIDATOR, PHONE_NUMBER_VALIDATOR, TEXT_LIMIT_VALIDATOR, POSTALCODE_VALIDATOR, UUID4_VALIDATOR } from '@digigov/form/validators/utils';
|
|
7
7
|
import { NUMBER_VALIDATOR } from '@digigov/form/validators/utils/number';
|
|
8
8
|
import { INT_VALIDATOR } from '@digigov/form/validators/utils/int';
|
|
9
9
|
dayjs.extend(customParseFormat);
|
|
@@ -26,7 +26,6 @@ export var getYUPTypeMap = function getYUPTypeMap() {
|
|
|
26
26
|
}).nullable().test(FILE_MAX_SIZE_VALIDATOR(field));
|
|
27
27
|
},
|
|
28
28
|
string: yup.string,
|
|
29
|
-
text: yup.string,
|
|
30
29
|
"boolean": yup["boolean"],
|
|
31
30
|
object: function object(field) {
|
|
32
31
|
return getYupObjectShape(field.extra.fields, yupTypeMap);
|
|
@@ -82,6 +81,15 @@ export var getYUPTypeMap = function getYUPTypeMap() {
|
|
|
82
81
|
otp: function otp(field) {
|
|
83
82
|
return yup.string().test(OTP_VALIDATOR(field));
|
|
84
83
|
},
|
|
84
|
+
text: function text(field) {
|
|
85
|
+
var _field$extra, _field$extra$limit, _field$extra2, _field$extra2$limit;
|
|
86
|
+
|
|
87
|
+
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)) {
|
|
88
|
+
return yup.string().test(TEXT_LIMIT_VALIDATOR(field));
|
|
89
|
+
} else {
|
|
90
|
+
return yup.string();
|
|
91
|
+
}
|
|
92
|
+
},
|
|
85
93
|
postal_code: function postal_code(field) {
|
|
86
94
|
return yup.string().test(POSTALCODE_VALIDATOR(field));
|
|
87
95
|
},
|
|
@@ -6,6 +6,7 @@ export * from '@digigov/form/validators/utils/otp';
|
|
|
6
6
|
export * from '@digigov/form/validators/utils/phone';
|
|
7
7
|
export * from '@digigov/form/validators/utils/postal_code';
|
|
8
8
|
export * from '@digigov/form/validators/utils/uuid4';
|
|
9
|
+
export * from '@digigov/form/validators/utils/text_limit';
|
|
9
10
|
export function getYupField(field, yupTypeMap) {
|
|
10
11
|
var yupField = yupTypeMap[(field === null || field === void 0 ? void 0 : field.type) || 'string'] || yupTypeMap['string'];
|
|
11
12
|
return yupField(field);
|
|
@@ -17,7 +18,7 @@ export function computeShape(fields, yupTypeMap, validatorRegistry) {
|
|
|
17
18
|
var yupField = getYupField(field, yupTypeMap);
|
|
18
19
|
|
|
19
20
|
if (field.condition) {
|
|
20
|
-
|
|
21
|
+
var _loop = function _loop(key) {
|
|
21
22
|
var then = void 0,
|
|
22
23
|
otherwise = void 0;
|
|
23
24
|
|
|
@@ -43,11 +44,24 @@ export function computeShape(fields, yupTypeMap, validatorRegistry) {
|
|
|
43
44
|
|
|
44
45
|
if (then || otherwise) {
|
|
45
46
|
yupField = yupField.when(key, {
|
|
46
|
-
is:
|
|
47
|
+
is: function is(val) {
|
|
48
|
+
//@ts-ignore
|
|
49
|
+
var is = field.condition[key].is;
|
|
50
|
+
|
|
51
|
+
if (is === val || Array.isArray(val) && val.includes(is)) {
|
|
52
|
+
return true;
|
|
53
|
+
} else {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
},
|
|
47
57
|
then: then,
|
|
48
58
|
otherwise: otherwise
|
|
49
59
|
});
|
|
50
60
|
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
for (var key in field.condition) {
|
|
64
|
+
_loop(key);
|
|
51
65
|
}
|
|
52
66
|
} else if (field.required) {
|
|
53
67
|
yupField = yupField.nullable().required('form.error.required');
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export function validateText(value, min, max) {
|
|
2
|
+
var validator;
|
|
3
|
+
|
|
4
|
+
if (min || max) {
|
|
5
|
+
if (value.length < min || value.length > max) {
|
|
6
|
+
return validator = false;
|
|
7
|
+
} else {
|
|
8
|
+
return validator = true;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return validator;
|
|
13
|
+
}
|
|
14
|
+
export var TEXT_LIMIT_VALIDATOR = function TEXT_LIMIT_VALIDATOR(field) {
|
|
15
|
+
var _field$extra, _field$extra$limit, _field$extra2, _field$extra2$limit;
|
|
16
|
+
|
|
17
|
+
var min = field === null || field === void 0 ? void 0 : (_field$extra = field.extra) === null || _field$extra === void 0 ? void 0 : (_field$extra$limit = _field$extra.limit) === null || _field$extra$limit === void 0 ? void 0 : _field$extra$limit.min;
|
|
18
|
+
var max = field === null || field === void 0 ? void 0 : (_field$extra2 = field.extra) === null || _field$extra2 === void 0 ? void 0 : (_field$extra2$limit = _field$extra2.limit) === null || _field$extra2$limit === void 0 ? void 0 : _field$extra2$limit.max;
|
|
19
|
+
return {
|
|
20
|
+
name: 'text-limit-validator',
|
|
21
|
+
message: function message(v) {
|
|
22
|
+
if (min || max) {
|
|
23
|
+
if (v.value.length < min) {
|
|
24
|
+
var _field$extra3, _field$extra3$limit;
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
key: 'form.error.text.less_than',
|
|
28
|
+
context: {
|
|
29
|
+
min: field === null || field === void 0 ? void 0 : (_field$extra3 = field.extra) === null || _field$extra3 === void 0 ? void 0 : (_field$extra3$limit = _field$extra3.limit) === null || _field$extra3$limit === void 0 ? void 0 : _field$extra3$limit.min
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (v.value.length > max) {
|
|
35
|
+
var _field$extra4, _field$extra4$limit;
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
key: 'form.error.text.more_than',
|
|
39
|
+
context: {
|
|
40
|
+
max: field === null || field === void 0 ? void 0 : (_field$extra4 = field.extra) === null || _field$extra4 === void 0 ? void 0 : (_field$extra4$limit = _field$extra4.limit) === null || _field$extra4$limit === void 0 ? void 0 : _field$extra4$limit.max
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
test: function test(value) {
|
|
47
|
+
if (!value) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return validateText(value, min, max);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
};
|
package/esm/Field/FieldBase.js
CHANGED
|
@@ -2,8 +2,8 @@ import _extends from "@babel/runtime/helpers/extends";
|
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
3
|
var _excluded = ["required", "name", "component", "wrapper", "control", "type", "controlled", "enabled", "editable", "defaultValue", "label", "extra", "layout", "error", "register"];
|
|
4
4
|
import React from 'react';
|
|
5
|
-
import { Controller } from 'react-hook-form';
|
|
6
5
|
import FieldBaseContainer from '@digigov/form/Field/FieldBaseContainer';
|
|
6
|
+
import { Controller } from 'react-hook-form';
|
|
7
7
|
export var FieldBase = function FieldBase(props) {
|
|
8
8
|
var required = props.required,
|
|
9
9
|
name = props.name,
|