@digigov/form 0.6.5 → 0.6.8
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 +24 -1
- package/Field/index.js +24 -7
- package/Questions/index.mdx +0 -2
- package/es/Field/index.js +24 -7
- package/es/Questions/index.mdx +0 -2
- package/es/index.js +1 -1
- package/es/inputs/Checkboxes/index.js +12 -2
- package/es/inputs/DateInput/index.js +6 -3
- package/es/inputs/FileInput/index.js +10 -3
- package/es/inputs/Input/index.js +7 -2
- package/es/inputs/Radio/index.js +12 -3
- package/es/inputs/Select/index.js +10 -3
- package/es/validators.js +120 -3
- package/es/validators.spec.js +52 -1
- package/esm/Field/index.js +24 -7
- package/esm/Questions/index.mdx +0 -2
- package/esm/index.js +2 -2
- package/esm/inputs/Checkboxes/index.js +12 -2
- package/esm/inputs/DateInput/index.js +6 -3
- package/esm/inputs/FileInput/index.js +10 -3
- package/esm/inputs/Input/index.js +7 -2
- package/esm/inputs/Radio/index.js +12 -3
- package/esm/inputs/Select/index.js +10 -3
- package/esm/validators.js +120 -3
- package/esm/validators.spec.js +52 -1
- package/index.js +1 -1
- package/inputs/Checkboxes/index.js +13 -2
- package/inputs/DateInput/index.js +6 -3
- package/inputs/FileInput/index.js +13 -3
- package/inputs/Input/index.js +7 -2
- package/inputs/Radio/index.js +14 -3
- package/inputs/Select/index.js +12 -3
- package/libs/form/src/Field/index.d.ts +2 -0
- package/libs/form/src/index.d.ts +1 -1
- package/libs/form/src/validators.d.ts +4 -0
- package/libs/ui/src/core/index.d.ts +0 -1
- package/libs/ui/src/locales/el.d.ts +4 -0
- package/package.json +2 -2
- package/validators.js +127 -3
- package/validators.spec.js +51 -0
- package/libs/ui/src/app/App.d.ts +0 -14
- package/libs/ui/src/app/CopyToClipboard.d.ts +0 -8
- package/libs/ui/src/app/Header/HeaderLogo.d.ts +0 -3
- package/libs/ui/src/app/Header/HeaderSection.d.ts +0 -5
- package/libs/ui/src/app/Header/HeaderTitle.d.ts +0 -5
- package/libs/ui/src/app/Header/index.d.ts +0 -11
- package/libs/ui/src/app/I18nText.d.ts +0 -10
- package/libs/ui/src/app/PhaseBannerHeader.d.ts +0 -8
- package/libs/ui/src/app/QrCodeScanner/index.d.ts +0 -29
- package/libs/ui/src/app/index.d.ts +0 -8
- package/libs/ui/src/core/PaginationLabel/index.d.ts +0 -21
- package/libs-ui/react-core/src/Header/index.d.ts +0 -10
- package/libs-ui/react-core/src/HeaderContent/index.d.ts +0 -9
- package/libs-ui/react-core/src/HeaderLogo/index.d.ts +0 -17
- package/libs-ui/react-core/src/HeaderSecondaryLogo/index.d.ts +0 -17
- package/libs-ui/react-core/src/HeaderSection/index.d.ts +0 -9
- package/libs-ui/react-core/src/HeaderSubtitle/index.d.ts +0 -9
- package/libs-ui/react-core/src/HeaderTitle/index.d.ts +0 -13
- package/libs-ui/react-core/src/PhaseBannerHeaderContainer/index.d.ts +0 -8
- package/libs-ui/react-extensions/src/admin/CopyToClipboardMessage/index.d.ts +0 -21
- package/libs-ui/react-extensions/src/admin/PaginationLabel/index.d.ts +0 -9
package/es/validators.spec.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { validateUUID4, validateIban } from '@digigov/form/validators';
|
|
1
|
+
import { validateUUID4, validateIban, validatePostalCode, validatePhoneNumber } from '@digigov/form/validators';
|
|
2
2
|
it('validates wrong uuid4 for empty value', function () {
|
|
3
3
|
expect(validateUUID4('')).toBe(false);
|
|
4
4
|
});
|
|
@@ -31,4 +31,55 @@ it('validates wrong iban for non existing country code', function () {
|
|
|
31
31
|
});
|
|
32
32
|
it('validates correct greek iban whithout country code', function () {
|
|
33
33
|
expect(validateIban('7801100800000008009825202', '')).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
it('validates wrong postal code without country code', function () {
|
|
36
|
+
expect(validatePostalCode('123', [])).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
it('validates wrong postal code with wrong country code', function () {
|
|
39
|
+
expect(validatePostalCode('123', ['FR'])).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
it('validates wrong postal code with greek country code', function () {
|
|
42
|
+
expect(validatePostalCode('123', ['GR'])).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
it('validates postal code with greek country code', function () {
|
|
45
|
+
expect(validatePostalCode('11143', ['GR'])).toBe(true);
|
|
46
|
+
});
|
|
47
|
+
it('validates phone number type landline with greek country code', function () {
|
|
48
|
+
expect(validatePhoneNumber('2102934896', ['GR'], 'landline')).toBe(true);
|
|
49
|
+
});
|
|
50
|
+
it('validates phone number type landline with ch country code', function () {
|
|
51
|
+
expect(validatePhoneNumber('2102934896', ['CH'], 'landline')).toBe(false);
|
|
52
|
+
});
|
|
53
|
+
it('validates phone number type landline with ch and gr countries code', function () {
|
|
54
|
+
expect(validatePhoneNumber('2102934896', ['GR', 'CH'], 'landline')).toBe(true);
|
|
55
|
+
});
|
|
56
|
+
it('validatesphone number type landline with ch and gr countries code', function () {
|
|
57
|
+
expect(validatePhoneNumber('41446681800', ['GR', 'CH'], 'landline')).toBe(true);
|
|
58
|
+
});
|
|
59
|
+
it('validates phone number type landline with ch and gr countries code but phone number is mobile', function () {
|
|
60
|
+
expect(validatePhoneNumber('2102934896', ['GR', 'CH'], 'mobile')).toBe(false);
|
|
61
|
+
});
|
|
62
|
+
it('validates phone number type mobile with ch and gr countries code', function () {
|
|
63
|
+
expect(validatePhoneNumber('6934100982', ['GR', 'CH'], 'mobile')).toBe(true);
|
|
64
|
+
});
|
|
65
|
+
it('validates phone number type mobile with gr country code', function () {
|
|
66
|
+
expect(validatePhoneNumber('6934100982', ['GR'], 'mobile')).toBe(true);
|
|
67
|
+
});
|
|
68
|
+
it('validates phone number type mobile with ch country code', function () {
|
|
69
|
+
expect(validatePhoneNumber('6934100982', ['CH'], 'mobile')).toBe(false);
|
|
70
|
+
});
|
|
71
|
+
it('validates phone number with no type and ch country code', function () {
|
|
72
|
+
expect(validatePhoneNumber('6934100982', ['CH'], null)).toBe(false);
|
|
73
|
+
});
|
|
74
|
+
it('validates phone number with no type and gr country code', function () {
|
|
75
|
+
expect(validatePhoneNumber('6934100982', ['gr'], null)).toBe(true);
|
|
76
|
+
});
|
|
77
|
+
it('validates phone number with no type and ch country code', function () {
|
|
78
|
+
expect(validatePhoneNumber('41446681800', ['CH'], null)).toBe(true);
|
|
79
|
+
});
|
|
80
|
+
it('validates phone number with no type and gr country code', function () {
|
|
81
|
+
expect(validatePhoneNumber('41446681800', ['gr'], null)).toBe(false);
|
|
82
|
+
});
|
|
83
|
+
it('validates phone number with no type and gr and ch countries code', function () {
|
|
84
|
+
expect(validatePhoneNumber('41446681800', ['gr', 'ch'], null)).toBe(true);
|
|
34
85
|
});
|
package/esm/Field/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
-
var _excluded = ["name", "component", "wrapper", "control", "type", "controlled", "enabled", "editable", "defaultValue", "label", "extra", "layout", "error", "register"],
|
|
3
|
+
var _excluded = ["required", "name", "component", "wrapper", "control", "type", "controlled", "enabled", "editable", "defaultValue", "label", "extra", "layout", "error", "register"],
|
|
4
4
|
_excluded2 = ["name", "children"];
|
|
5
5
|
import React, { useContext, useMemo } from 'react';
|
|
6
6
|
import { ConditionalField } from '@digigov/form/Field/ConditionalField';
|
|
@@ -55,7 +55,8 @@ var ALTERNATIVE_COMPONENTS = {
|
|
|
55
55
|
};
|
|
56
56
|
|
|
57
57
|
var FieldContainer = function FieldContainer(_ref) {
|
|
58
|
-
var
|
|
58
|
+
var name = _ref.name,
|
|
59
|
+
wrapper = _ref.wrapper,
|
|
59
60
|
label = _ref.label,
|
|
60
61
|
children = _ref.children,
|
|
61
62
|
error = _ref.error;
|
|
@@ -68,18 +69,23 @@ var FieldContainer = function FieldContainer(_ref) {
|
|
|
68
69
|
error: !!error
|
|
69
70
|
}, /*#__PURE__*/React.createElement(CoreFieldset, null, /*#__PURE__*/React.createElement(FieldsetLegend, {
|
|
70
71
|
size: "s"
|
|
71
|
-
}, label && label.primary, label && label.secondary && /*#__PURE__*/React.createElement(Hint, null, t(label.secondary)), error && /*#__PURE__*/React.createElement(ErrorMessage,
|
|
72
|
+
}, label && label.primary, label && label.secondary && /*#__PURE__*/React.createElement(Hint, null, t(label.secondary)), error && /*#__PURE__*/React.createElement(ErrorMessage, {
|
|
73
|
+
id: "".concat(name, "-error")
|
|
74
|
+
}, t((error === null || error === void 0 ? void 0 : error.message) || ''))), children));
|
|
72
75
|
} else {
|
|
73
76
|
return /*#__PURE__*/React.createElement(CoreField, {
|
|
74
77
|
error: !!error
|
|
75
78
|
}, /*#__PURE__*/React.createElement(CoreLabel, null, label && /*#__PURE__*/React.createElement(Label, {
|
|
76
79
|
label: label
|
|
77
|
-
}), error && /*#__PURE__*/React.createElement(ErrorMessage,
|
|
80
|
+
}), error && /*#__PURE__*/React.createElement(ErrorMessage, {
|
|
81
|
+
id: "".concat(name, "-error")
|
|
82
|
+
}, t((error === null || error === void 0 ? void 0 : error.message) || '')), children));
|
|
78
83
|
}
|
|
79
84
|
};
|
|
80
85
|
|
|
81
86
|
export var FieldBase = function FieldBase(props) {
|
|
82
|
-
var
|
|
87
|
+
var required = props.required,
|
|
88
|
+
name = props.name,
|
|
83
89
|
Component = props.component,
|
|
84
90
|
wrapper = props.wrapper,
|
|
85
91
|
control = props.control,
|
|
@@ -107,7 +113,8 @@ export var FieldBase = function FieldBase(props) {
|
|
|
107
113
|
label: label,
|
|
108
114
|
layout: layout,
|
|
109
115
|
error: error,
|
|
110
|
-
wrapper: wrapper
|
|
116
|
+
wrapper: wrapper,
|
|
117
|
+
name: name
|
|
111
118
|
}, /*#__PURE__*/React.createElement(Controller, {
|
|
112
119
|
control: control,
|
|
113
120
|
name: name,
|
|
@@ -124,6 +131,9 @@ export var FieldBase = function FieldBase(props) {
|
|
|
124
131
|
extra: extra,
|
|
125
132
|
error: !!error,
|
|
126
133
|
type: type,
|
|
134
|
+
"aria-required": !!required,
|
|
135
|
+
"aria-describedby": error && "".concat(name, "-error"),
|
|
136
|
+
required: required,
|
|
127
137
|
disabled: editable === false
|
|
128
138
|
}, componentProps));
|
|
129
139
|
}
|
|
@@ -134,7 +144,8 @@ export var FieldBase = function FieldBase(props) {
|
|
|
134
144
|
label: label,
|
|
135
145
|
layout: layout,
|
|
136
146
|
error: error,
|
|
137
|
-
wrapper: wrapper
|
|
147
|
+
wrapper: wrapper,
|
|
148
|
+
name: name
|
|
138
149
|
}, Component !== null && Component !== void 0 && Component.render ? /*#__PURE__*/React.createElement(Component, _extends({
|
|
139
150
|
name: name,
|
|
140
151
|
ref: register,
|
|
@@ -142,6 +153,9 @@ export var FieldBase = function FieldBase(props) {
|
|
|
142
153
|
error: !!error,
|
|
143
154
|
extra: extra,
|
|
144
155
|
type: type,
|
|
156
|
+
"aria-required": !!required,
|
|
157
|
+
"aria-describedby": error && "".concat(name, "-error"),
|
|
158
|
+
required: required,
|
|
145
159
|
disabled: editable === false
|
|
146
160
|
}, componentProps)) : /*#__PURE__*/React.createElement(Component, _extends({
|
|
147
161
|
name: name,
|
|
@@ -150,6 +164,9 @@ export var FieldBase = function FieldBase(props) {
|
|
|
150
164
|
error: !!error,
|
|
151
165
|
extra: extra,
|
|
152
166
|
type: type,
|
|
167
|
+
"aria-required": !!required,
|
|
168
|
+
"aria-describedby": error && "".concat(name, "-error"),
|
|
169
|
+
required: required,
|
|
153
170
|
disabled: editable === false
|
|
154
171
|
}, componentProps)));
|
|
155
172
|
};
|
package/esm/Questions/index.mdx
CHANGED
|
@@ -10,8 +10,6 @@ import Questions, {
|
|
|
10
10
|
StepTitle,
|
|
11
11
|
} from '@digigov/form/Questions';
|
|
12
12
|
import { Field } from '@digigov/form';
|
|
13
|
-
import PropsDoc from '@docs-components/propsDoc';
|
|
14
|
-
import StylesDoc from '@docs-components/stylesDoc';
|
|
15
13
|
const steps = [
|
|
16
14
|
{
|
|
17
15
|
name: 'intro',
|
package/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license Digigov v0.6.
|
|
1
|
+
/** @license Digigov v0.6.8
|
|
2
2
|
*
|
|
3
3
|
* This source code is licensed under the BSD-2-Clause license found in the
|
|
4
4
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -55,7 +55,7 @@ export var FormBase = /*#__PURE__*/React.forwardRef(function FormBase(_ref, ref)
|
|
|
55
55
|
form.setError(key, errors[key]);
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
}, []);
|
|
58
|
+
}, [onSubmit]);
|
|
59
59
|
var ctx = {
|
|
60
60
|
fieldsMap: fieldsMap,
|
|
61
61
|
fieldsetsMap: fieldsetsMap,
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["name", "onChange", "value", "extra", "disabled"];
|
|
2
4
|
import React from 'react';
|
|
3
5
|
import { useTranslation } from '@digigov/ui/app/i18n';
|
|
4
6
|
import CoreCheckboxes from '@digigov/react-core/Checkbox';
|
|
@@ -11,7 +13,9 @@ export var Checkboxes = function Checkboxes(_ref) {
|
|
|
11
13
|
_ref$extra = _ref.extra,
|
|
12
14
|
options = _ref$extra.options,
|
|
13
15
|
className = _ref$extra.className,
|
|
14
|
-
disabled = _ref.disabled
|
|
16
|
+
disabled = _ref.disabled,
|
|
17
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
18
|
+
|
|
15
19
|
if (!value) value = [];
|
|
16
20
|
|
|
17
21
|
var handleChange = function handleChange(optionValue) {
|
|
@@ -48,7 +52,13 @@ export var Checkboxes = function Checkboxes(_ref) {
|
|
|
48
52
|
,
|
|
49
53
|
checked: value.includes(option.value),
|
|
50
54
|
onChange: handleChange(option.value)
|
|
51
|
-
}, option
|
|
55
|
+
}, option, _extends({}, props, {
|
|
56
|
+
defaultValue: undefined,
|
|
57
|
+
onBlur: undefined,
|
|
58
|
+
required: undefined,
|
|
59
|
+
'aria-describedby': undefined,
|
|
60
|
+
type: 'checkbox'
|
|
61
|
+
})), option.label && option.label.primary && t(option.label.primary) || value, option.label && option.label.secondary && /*#__PURE__*/React.createElement(Hint, null, t(option.label.secondary)));
|
|
52
62
|
}));
|
|
53
63
|
};
|
|
54
64
|
export default Checkboxes;
|
|
@@ -123,7 +123,8 @@ export var DateInput = function DateInput(_ref2) {
|
|
|
123
123
|
width: 2,
|
|
124
124
|
name: "".concat(name, "-day"),
|
|
125
125
|
maxlength: "2",
|
|
126
|
-
disabled: props.disabled
|
|
126
|
+
disabled: props.disabled,
|
|
127
|
+
"aria-required": props['aria-required']
|
|
127
128
|
}), /*#__PURE__*/React.createElement(DatePart, {
|
|
128
129
|
label: t('form.label.month'),
|
|
129
130
|
onChange: date.setMonth,
|
|
@@ -134,7 +135,8 @@ export var DateInput = function DateInput(_ref2) {
|
|
|
134
135
|
width: 2,
|
|
135
136
|
name: "".concat(props.name, "-month"),
|
|
136
137
|
maxlength: "2",
|
|
137
|
-
disabled: props.disabled
|
|
138
|
+
disabled: props.disabled,
|
|
139
|
+
"aria-required": props['aria-required']
|
|
138
140
|
}), /*#__PURE__*/React.createElement(DatePart, {
|
|
139
141
|
label: t('form.label.year'),
|
|
140
142
|
onChange: date.setYear,
|
|
@@ -142,7 +144,8 @@ export var DateInput = function DateInput(_ref2) {
|
|
|
142
144
|
width: 4,
|
|
143
145
|
name: "".concat(props.name, "-year"),
|
|
144
146
|
maxlength: "4",
|
|
145
|
-
disabled: props.disabled
|
|
147
|
+
disabled: props.disabled,
|
|
148
|
+
"aria-required": props['aria-required']
|
|
146
149
|
}));
|
|
147
150
|
};
|
|
148
151
|
export default DateInput;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
1
2
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
+
var _excluded = ["name", "extra", "disabled", "type"];
|
|
2
5
|
import React, { useState } from 'react';
|
|
3
6
|
import clsx from 'clsx';
|
|
4
7
|
import { useTranslation } from '@digigov/ui/app/i18n';
|
|
@@ -9,7 +12,9 @@ export var FileInput = /*#__PURE__*/React.forwardRef(function FileInput(_ref, re
|
|
|
9
12
|
var name = _ref.name,
|
|
10
13
|
_ref$extra = _ref.extra,
|
|
11
14
|
extra = _ref$extra === void 0 ? {} : _ref$extra,
|
|
12
|
-
disabled = _ref.disabled
|
|
15
|
+
disabled = _ref.disabled,
|
|
16
|
+
type = _ref.type,
|
|
17
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
13
18
|
|
|
14
19
|
var _useTranslation = useTranslation(),
|
|
15
20
|
t = _useTranslation.t;
|
|
@@ -25,7 +30,7 @@ export var FileInput = /*#__PURE__*/React.forwardRef(function FileInput(_ref, re
|
|
|
25
30
|
tabIndex: 0,
|
|
26
31
|
role: "button",
|
|
27
32
|
className: clsx(extra.className, files.length === 0 && ['govgr-btn', 'govgr-btn-primary'], files.length > 0 && 'govgr-link', true && 'govgr-label-file')
|
|
28
|
-
}, /*#__PURE__*/React.createElement("input", {
|
|
33
|
+
}, /*#__PURE__*/React.createElement("input", _extends({
|
|
29
34
|
ref: ref,
|
|
30
35
|
type: "file",
|
|
31
36
|
name: name,
|
|
@@ -42,6 +47,8 @@ export var FileInput = /*#__PURE__*/React.forwardRef(function FileInput(_ref, re
|
|
|
42
47
|
});
|
|
43
48
|
setFiles(selectedFiles);
|
|
44
49
|
}
|
|
45
|
-
}
|
|
50
|
+
}, _extends({}, props, {
|
|
51
|
+
required: undefined
|
|
52
|
+
}))), files.length ? t('upload.change_file') : t('upload.choose_file')));
|
|
46
53
|
});
|
|
47
54
|
export default FileInput;
|
|
@@ -37,14 +37,19 @@ export var Input = /*#__PURE__*/React.forwardRef(function WrappedInput(_ref, ref
|
|
|
37
37
|
className: className,
|
|
38
38
|
rows: rows,
|
|
39
39
|
ref: ref
|
|
40
|
-
}, props
|
|
40
|
+
}, _extends({}, props, {
|
|
41
|
+
required: undefined,
|
|
42
|
+
type: fieldType
|
|
43
|
+
})));
|
|
41
44
|
} else {
|
|
42
45
|
return /*#__PURE__*/React.createElement(TextInput, _extends({
|
|
43
46
|
name: name,
|
|
44
47
|
type: fieldType,
|
|
45
48
|
className: className,
|
|
46
49
|
ref: ref
|
|
47
|
-
}, props
|
|
50
|
+
}, _extends({}, props, {
|
|
51
|
+
required: undefined
|
|
52
|
+
})));
|
|
48
53
|
}
|
|
49
54
|
});
|
|
50
55
|
export default Input;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
1
2
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
+
var _excluded = ["register", "name", "control", "extra", "disabled"];
|
|
2
5
|
import React, { useState } from 'react';
|
|
3
6
|
import Radio from '@digigov/react-core/Radio';
|
|
4
7
|
import RadioItem from '@digigov/react-core/RadioItem';
|
|
@@ -12,7 +15,9 @@ export var RadioButtonsGroup = function RadioButtonsGroup(_ref) {
|
|
|
12
15
|
_ref$extra = _ref.extra,
|
|
13
16
|
options = _ref$extra.options,
|
|
14
17
|
className = _ref$extra.className,
|
|
15
|
-
disabled = _ref.disabled
|
|
18
|
+
disabled = _ref.disabled,
|
|
19
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
20
|
+
|
|
16
21
|
var currentValue = useWatch({
|
|
17
22
|
control: control,
|
|
18
23
|
name: name
|
|
@@ -33,13 +38,17 @@ export var RadioButtonsGroup = function RadioButtonsGroup(_ref) {
|
|
|
33
38
|
var label = _ref2.label,
|
|
34
39
|
v = _ref2.value,
|
|
35
40
|
optionDisabled = _ref2.disabled;
|
|
36
|
-
return /*#__PURE__*/React.createElement(RadioItem, {
|
|
41
|
+
return /*#__PURE__*/React.createElement(RadioItem, _extends({
|
|
37
42
|
ref: register,
|
|
38
43
|
key: v,
|
|
39
44
|
name: name,
|
|
40
45
|
value: v,
|
|
41
46
|
disabled: disabled || optionDisabled
|
|
42
|
-
},
|
|
47
|
+
}, _extends({}, props, {
|
|
48
|
+
required: undefined,
|
|
49
|
+
'aria-describedby': undefined,
|
|
50
|
+
type: 'radio'
|
|
51
|
+
})), label && label.primary && t(label.primary) || v, label && label.secondary && /*#__PURE__*/React.createElement(Hint, null, t(label.secondary)));
|
|
43
52
|
}));
|
|
44
53
|
};
|
|
45
54
|
export default RadioButtonsGroup;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["name", "extra", "disabled"];
|
|
1
4
|
import React from 'react';
|
|
2
5
|
import CoreSelect from '@digigov/react-core/Select';
|
|
3
6
|
import SelectOption from '@digigov/react-core/SelectOption';
|
|
@@ -6,13 +9,17 @@ export var Select = /*#__PURE__*/React.forwardRef(function WrappedSelect(_ref, r
|
|
|
6
9
|
_ref$extra = _ref.extra,
|
|
7
10
|
options = _ref$extra.options,
|
|
8
11
|
className = _ref$extra.className,
|
|
9
|
-
disabled = _ref.disabled
|
|
10
|
-
|
|
12
|
+
disabled = _ref.disabled,
|
|
13
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
14
|
+
|
|
15
|
+
return /*#__PURE__*/React.createElement(CoreSelect, _extends({
|
|
11
16
|
className: className,
|
|
12
17
|
ref: ref,
|
|
13
18
|
name: name,
|
|
14
19
|
disabled: disabled
|
|
15
|
-
},
|
|
20
|
+
}, _extends({}, props, {
|
|
21
|
+
required: undefined
|
|
22
|
+
})), options.map(function (_ref2) {
|
|
16
23
|
var value = _ref2.value,
|
|
17
24
|
label = _ref2.label;
|
|
18
25
|
return /*#__PURE__*/React.createElement(SelectOption, {
|
package/esm/validators.js
CHANGED
|
@@ -14,6 +14,19 @@ import dayjs from 'dayjs';
|
|
|
14
14
|
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
15
15
|
dayjs.extend(customParseFormat);
|
|
16
16
|
var DEFAULT_FILE_MAX_SIZE = 10000000;
|
|
17
|
+
export function validatePostalCode(number, countries) {
|
|
18
|
+
if (!countries) {
|
|
19
|
+
return false;
|
|
20
|
+
} else {
|
|
21
|
+
if (countries.length === 1 && countries[0].toUpperCase() === 'GR') {
|
|
22
|
+
// Greek postal code must be 5 digits long and shouldn't start with 0 or 9.
|
|
23
|
+
var CODE_REGEX = /^[12345678][0-9]{4}$/;
|
|
24
|
+
return CODE_REGEX.test(number);
|
|
25
|
+
} else {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
17
30
|
export function validateAFM(afm) {
|
|
18
31
|
if (afm.length !== 9) {
|
|
19
32
|
// "afm should be 9 digits"
|
|
@@ -38,6 +51,58 @@ export function validateAFM(afm) {
|
|
|
38
51
|
var valid = calc % 10 === d9;
|
|
39
52
|
return valid;
|
|
40
53
|
}
|
|
54
|
+
export function validatePhoneNumber(phoneNumber) {
|
|
55
|
+
var countries = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['gr'];
|
|
56
|
+
var typeOfPhoneNumber = arguments.length > 2 ? arguments[2] : undefined;
|
|
57
|
+
var phoneUtil = gPhoneNumber.PhoneNumberUtil.getInstance();
|
|
58
|
+
|
|
59
|
+
if (!countries || countries.length === 0) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return countries.some(function (country) {
|
|
64
|
+
try {
|
|
65
|
+
var phone = phoneUtil.parse(phoneNumber, country.toUpperCase());
|
|
66
|
+
|
|
67
|
+
if (phoneUtil.isValidNumber(phone)) {
|
|
68
|
+
if (typeOfPhoneNumber) {
|
|
69
|
+
if (matchTypeOfPhoneNumber(phone, typeOfPhoneNumber, phoneUtil)) {
|
|
70
|
+
return true;
|
|
71
|
+
} else {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return false;
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error(error);
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
var phoneNumberTypes = {
|
|
87
|
+
0: 'landline',
|
|
88
|
+
1: 'mobile',
|
|
89
|
+
2: 'landline_or_mobile'
|
|
90
|
+
};
|
|
91
|
+
export function matchTypeOfPhoneNumber(phone, type, phoneUtil) {
|
|
92
|
+
try {
|
|
93
|
+
var phoneNumberType = phoneUtil.getNumberType(phone);
|
|
94
|
+
var numberType = phoneNumberTypes[phoneNumberType];
|
|
95
|
+
|
|
96
|
+
if (numberType === 'landline_or_mobile' || numberType === type) {
|
|
97
|
+
return true;
|
|
98
|
+
} else {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
} catch (error) {
|
|
102
|
+
console.error(error);
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
41
106
|
|
|
42
107
|
function validateMobile(value) {
|
|
43
108
|
var phoneUtil = gPhoneNumber.PhoneNumberUtil.getInstance();
|
|
@@ -69,6 +134,23 @@ function validateMobile(value) {
|
|
|
69
134
|
}
|
|
70
135
|
}
|
|
71
136
|
|
|
137
|
+
var POSTALCODE_VALIDATOR = function POSTALCODE_VALIDATOR(field) {
|
|
138
|
+
var _field$extra;
|
|
139
|
+
|
|
140
|
+
var countryCode = field === null || field === void 0 ? void 0 : (_field$extra = field.extra) === null || _field$extra === void 0 ? void 0 : _field$extra.countries;
|
|
141
|
+
return {
|
|
142
|
+
name: 'postal-code-validator',
|
|
143
|
+
message: 'form.error.postalCode',
|
|
144
|
+
test: function test(value) {
|
|
145
|
+
if (!value) {
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return validatePostalCode(value, countryCode);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
|
|
72
154
|
var MOBILE_PHONE_VALIDATOR = {
|
|
73
155
|
name: 'mobile-phone-validator',
|
|
74
156
|
message: 'form.error.mobile_phone',
|
|
@@ -80,6 +162,35 @@ var MOBILE_PHONE_VALIDATOR = {
|
|
|
80
162
|
return true;
|
|
81
163
|
}
|
|
82
164
|
};
|
|
165
|
+
|
|
166
|
+
var PHONE_NUMBER_VALIDATOR = function PHONE_NUMBER_VALIDATOR(field) {
|
|
167
|
+
var _field$extra2, _field$extra3;
|
|
168
|
+
|
|
169
|
+
var countryCode = field === null || field === void 0 ? void 0 : (_field$extra2 = field.extra) === null || _field$extra2 === void 0 ? void 0 : _field$extra2.countries;
|
|
170
|
+
var typeOfPhone = field === null || field === void 0 ? void 0 : (_field$extra3 = field.extra) === null || _field$extra3 === void 0 ? void 0 : _field$extra3.phoneType;
|
|
171
|
+
return {
|
|
172
|
+
name: 'phone-number-validator',
|
|
173
|
+
message: function message() {
|
|
174
|
+
if (typeOfPhone === 'mobile') {
|
|
175
|
+
return 'form.error.mobile_phone';
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (typeOfPhone === 'landline') {
|
|
179
|
+
return 'form.error.landline';
|
|
180
|
+
} else {
|
|
181
|
+
return 'form.error.phone_number';
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
test: function test(value) {
|
|
185
|
+
if (!value) {
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return validatePhoneNumber(value, countryCode, typeOfPhone);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
|
|
83
194
|
var AFM_VALIDATOR = {
|
|
84
195
|
name: 'afm-validator',
|
|
85
196
|
message: 'form.error.afm',
|
|
@@ -267,14 +378,14 @@ export function validateIban(value, countryCode) {
|
|
|
267
378
|
}
|
|
268
379
|
|
|
269
380
|
var IBAN_VALIDATOR = function IBAN_VALIDATOR(field) {
|
|
270
|
-
var _field$
|
|
381
|
+
var _field$extra4;
|
|
271
382
|
|
|
272
|
-
var countryCode = field === null || field === void 0 ? void 0 : (_field$
|
|
383
|
+
var countryCode = field === null || field === void 0 ? void 0 : (_field$extra4 = field.extra) === null || _field$extra4 === void 0 ? void 0 : _field$extra4.country;
|
|
273
384
|
return {
|
|
274
385
|
name: 'iban-validator',
|
|
275
386
|
message: 'form.error.iban',
|
|
276
387
|
test: function test(value) {
|
|
277
|
-
if (!value
|
|
388
|
+
if (!value) {
|
|
278
389
|
return true;
|
|
279
390
|
}
|
|
280
391
|
|
|
@@ -418,9 +529,15 @@ var getYUPTypeMap = function getYUPTypeMap() {
|
|
|
418
529
|
iban: function iban(field) {
|
|
419
530
|
return yup.string().test(IBAN_VALIDATOR(field));
|
|
420
531
|
},
|
|
532
|
+
postal_code: function postal_code(field) {
|
|
533
|
+
return yup.string().test(POSTALCODE_VALIDATOR(field));
|
|
534
|
+
},
|
|
421
535
|
mobile_phone: function mobile_phone() {
|
|
422
536
|
return yup.string().test(MOBILE_PHONE_VALIDATOR);
|
|
423
537
|
},
|
|
538
|
+
phone_number: function phone_number(field) {
|
|
539
|
+
return yup.string().test(PHONE_NUMBER_VALIDATOR(field));
|
|
540
|
+
},
|
|
424
541
|
'choice:multiple': function choiceMultiple() {
|
|
425
542
|
return yup.array().of(yup.string()).nullable();
|
|
426
543
|
},
|
package/esm/validators.spec.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { validateUUID4, validateIban } from '@digigov/form/validators';
|
|
1
|
+
import { validateUUID4, validateIban, validatePostalCode, validatePhoneNumber } from '@digigov/form/validators';
|
|
2
2
|
it('validates wrong uuid4 for empty value', function () {
|
|
3
3
|
expect(validateUUID4('')).toBe(false);
|
|
4
4
|
});
|
|
@@ -31,4 +31,55 @@ it('validates wrong iban for non existing country code', function () {
|
|
|
31
31
|
});
|
|
32
32
|
it('validates correct greek iban whithout country code', function () {
|
|
33
33
|
expect(validateIban('7801100800000008009825202', '')).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
it('validates wrong postal code without country code', function () {
|
|
36
|
+
expect(validatePostalCode('123', [])).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
it('validates wrong postal code with wrong country code', function () {
|
|
39
|
+
expect(validatePostalCode('123', ['FR'])).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
it('validates wrong postal code with greek country code', function () {
|
|
42
|
+
expect(validatePostalCode('123', ['GR'])).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
it('validates postal code with greek country code', function () {
|
|
45
|
+
expect(validatePostalCode('11143', ['GR'])).toBe(true);
|
|
46
|
+
});
|
|
47
|
+
it('validates phone number type landline with greek country code', function () {
|
|
48
|
+
expect(validatePhoneNumber('2102934896', ['GR'], 'landline')).toBe(true);
|
|
49
|
+
});
|
|
50
|
+
it('validates phone number type landline with ch country code', function () {
|
|
51
|
+
expect(validatePhoneNumber('2102934896', ['CH'], 'landline')).toBe(false);
|
|
52
|
+
});
|
|
53
|
+
it('validates phone number type landline with ch and gr countries code', function () {
|
|
54
|
+
expect(validatePhoneNumber('2102934896', ['GR', 'CH'], 'landline')).toBe(true);
|
|
55
|
+
});
|
|
56
|
+
it('validatesphone number type landline with ch and gr countries code', function () {
|
|
57
|
+
expect(validatePhoneNumber('41446681800', ['GR', 'CH'], 'landline')).toBe(true);
|
|
58
|
+
});
|
|
59
|
+
it('validates phone number type landline with ch and gr countries code but phone number is mobile', function () {
|
|
60
|
+
expect(validatePhoneNumber('2102934896', ['GR', 'CH'], 'mobile')).toBe(false);
|
|
61
|
+
});
|
|
62
|
+
it('validates phone number type mobile with ch and gr countries code', function () {
|
|
63
|
+
expect(validatePhoneNumber('6934100982', ['GR', 'CH'], 'mobile')).toBe(true);
|
|
64
|
+
});
|
|
65
|
+
it('validates phone number type mobile with gr country code', function () {
|
|
66
|
+
expect(validatePhoneNumber('6934100982', ['GR'], 'mobile')).toBe(true);
|
|
67
|
+
});
|
|
68
|
+
it('validates phone number type mobile with ch country code', function () {
|
|
69
|
+
expect(validatePhoneNumber('6934100982', ['CH'], 'mobile')).toBe(false);
|
|
70
|
+
});
|
|
71
|
+
it('validates phone number with no type and ch country code', function () {
|
|
72
|
+
expect(validatePhoneNumber('6934100982', ['CH'], null)).toBe(false);
|
|
73
|
+
});
|
|
74
|
+
it('validates phone number with no type and gr country code', function () {
|
|
75
|
+
expect(validatePhoneNumber('6934100982', ['gr'], null)).toBe(true);
|
|
76
|
+
});
|
|
77
|
+
it('validates phone number with no type and ch country code', function () {
|
|
78
|
+
expect(validatePhoneNumber('41446681800', ['CH'], null)).toBe(true);
|
|
79
|
+
});
|
|
80
|
+
it('validates phone number with no type and gr country code', function () {
|
|
81
|
+
expect(validatePhoneNumber('41446681800', ['gr'], null)).toBe(false);
|
|
82
|
+
});
|
|
83
|
+
it('validates phone number with no type and gr and ch countries code', function () {
|
|
84
|
+
expect(validatePhoneNumber('41446681800', ['gr', 'ch'], null)).toBe(true);
|
|
34
85
|
});
|
package/index.js
CHANGED
|
@@ -9,6 +9,8 @@ exports["default"] = exports.Checkboxes = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
11
|
|
|
12
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
13
|
+
|
|
12
14
|
var _react = _interopRequireDefault(require("react"));
|
|
13
15
|
|
|
14
16
|
var _i18n = require("@digigov/ui/app/i18n");
|
|
@@ -19,6 +21,8 @@ var _CheckboxItem = _interopRequireDefault(require("@digigov/react-core/Checkbox
|
|
|
19
21
|
|
|
20
22
|
var _Hint = _interopRequireDefault(require("@digigov/react-core/Hint"));
|
|
21
23
|
|
|
24
|
+
var _excluded = ["name", "onChange", "value", "extra", "disabled"];
|
|
25
|
+
|
|
22
26
|
var Checkboxes = function Checkboxes(_ref) {
|
|
23
27
|
var name = _ref.name,
|
|
24
28
|
onChange = _ref.onChange,
|
|
@@ -26,7 +30,8 @@ var Checkboxes = function Checkboxes(_ref) {
|
|
|
26
30
|
_ref$extra = _ref.extra,
|
|
27
31
|
options = _ref$extra.options,
|
|
28
32
|
className = _ref$extra.className,
|
|
29
|
-
disabled = _ref.disabled
|
|
33
|
+
disabled = _ref.disabled,
|
|
34
|
+
props = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
|
|
30
35
|
if (!value) value = [];
|
|
31
36
|
|
|
32
37
|
var handleChange = function handleChange(optionValue) {
|
|
@@ -63,7 +68,13 @@ var Checkboxes = function Checkboxes(_ref) {
|
|
|
63
68
|
,
|
|
64
69
|
checked: value.includes(option.value),
|
|
65
70
|
onChange: handleChange(option.value)
|
|
66
|
-
}, option
|
|
71
|
+
}, option, (0, _extends2["default"])({}, props, {
|
|
72
|
+
defaultValue: undefined,
|
|
73
|
+
onBlur: undefined,
|
|
74
|
+
required: undefined,
|
|
75
|
+
'aria-describedby': undefined,
|
|
76
|
+
type: 'checkbox'
|
|
77
|
+
})), option.label && option.label.primary && t(option.label.primary) || value, option.label && option.label.secondary && /*#__PURE__*/_react["default"].createElement(_Hint["default"], null, t(option.label.secondary)));
|
|
67
78
|
}));
|
|
68
79
|
};
|
|
69
80
|
|