cozy-ui-plus 4.3.0 → 4.4.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 +6 -0
- package/dist/Contacts/AddModal/ContactForm/FieldInputLayout.js +2 -1
- package/dist/Contacts/AddModal/ContactForm/helpers.js +16 -6
- package/dist/Contacts/AddModal/ContactForm/locales/index.js +8 -4
- package/dist/src/Contacts/AddModal/ContactForm/FieldInputLayout.d.ts +2 -1
- package/package.json +2 -2
- package/src/Contacts/AddModal/ContactForm/FieldInputLayout.jsx +2 -1
- package/src/Contacts/AddModal/ContactForm/helpers.js +25 -11
- package/src/Contacts/AddModal/ContactForm/helpers.spec.js +10 -1
- package/src/Contacts/AddModal/ContactForm/locales/en.json +2 -1
- package/src/Contacts/AddModal/ContactForm/locales/fr.json +2 -1
- package/src/Contacts/AddModal/ContactForm/locales/ru.json +2 -1
- package/src/Contacts/AddModal/ContactForm/locales/vi.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [4.4.0](https://github.com/cozy/cozy-libs/compare/cozy-ui-plus@4.3.0...cozy-ui-plus@4.4.0) (2026-01-15)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **ContactForm:** Add `validate` attr on fields ([d8f36a0](https://github.com/cozy/cozy-libs/commit/d8f36a03c7474ebe581691d376d4b7b8a107a22a))
|
|
11
|
+
|
|
6
12
|
# [4.3.0](https://github.com/cozy/cozy-libs/compare/cozy-ui-plus@4.2.0...cozy-ui-plus@4.3.0) (2026-01-14)
|
|
7
13
|
|
|
8
14
|
### Features
|
|
@@ -29,7 +29,7 @@ var _helpers = require("./helpers");
|
|
|
29
29
|
|
|
30
30
|
var _locales = require("./locales");
|
|
31
31
|
|
|
32
|
-
var _excluded = ["layout", "icon", "isSecondary"],
|
|
32
|
+
var _excluded = ["layout", "icon", "isSecondary", "validate"],
|
|
33
33
|
_excluded2 = ["name", "label"];
|
|
34
34
|
|
|
35
35
|
var FieldInputLayout = function FieldInputLayout(_ref) {
|
|
@@ -37,6 +37,7 @@ var FieldInputLayout = function FieldInputLayout(_ref) {
|
|
|
37
37
|
layout = _ref$attributes.layout,
|
|
38
38
|
icon = _ref$attributes.icon,
|
|
39
39
|
isSecondary = _ref$attributes.isSecondary,
|
|
40
|
+
validate = _ref$attributes.validate,
|
|
40
41
|
attributes = (0, _objectWithoutProperties2.default)(_ref$attributes, _excluded),
|
|
41
42
|
contacts = _ref.contacts,
|
|
42
43
|
showSecondaryFields = _ref.showSecondaryFields,
|
|
@@ -87,15 +87,25 @@ exports.makeIsRequiredError = makeIsRequiredError;
|
|
|
87
87
|
|
|
88
88
|
var validateFields = function validateFields(values, fields, t) {
|
|
89
89
|
var errors = {};
|
|
90
|
-
var fieldsRequired = fields.filter(function (field) {
|
|
91
|
-
return field.required;
|
|
92
|
-
});
|
|
93
90
|
|
|
94
91
|
var _values = getFirstValueIfArray(values);
|
|
95
92
|
|
|
96
|
-
|
|
97
|
-
if
|
|
98
|
-
|
|
93
|
+
fields.forEach(function (field) {
|
|
94
|
+
// test if required fields are empty
|
|
95
|
+
if (field.required) {
|
|
96
|
+
if (!(0, _get.default)(_values, field.name)) {
|
|
97
|
+
errors[field.name] = field.layout === 'array' ? [(0, _defineProperty2.default)({}, field.name, t('Contacts.AddModal.ContactForm.fields.required'))] : t('Contacts.AddModal.ContactForm.fields.required');
|
|
98
|
+
}
|
|
99
|
+
} // test if validate fn on field is verified
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
if (field.validate) {
|
|
103
|
+
var fieldValue = _values[field.name];
|
|
104
|
+
var isFieldValid = field.validate(fieldValue);
|
|
105
|
+
|
|
106
|
+
if (!isFieldValid) {
|
|
107
|
+
errors[field.name] = t('Contacts.AddModal.ContactForm.fields.not-valid');
|
|
108
|
+
}
|
|
99
109
|
}
|
|
100
110
|
});
|
|
101
111
|
return errors;
|
|
@@ -32,7 +32,8 @@ var en = {
|
|
|
32
32
|
relationship: "Relationship",
|
|
33
33
|
note: "Notes",
|
|
34
34
|
label: "Label",
|
|
35
|
-
required: "All required fields must be filled in"
|
|
35
|
+
required: "All required fields must be filled in",
|
|
36
|
+
"not-valid": "Some fields are not filled correctly"
|
|
36
37
|
},
|
|
37
38
|
label: {
|
|
38
39
|
none: "None",
|
|
@@ -107,7 +108,8 @@ var fr = {
|
|
|
107
108
|
relationship: "Relation",
|
|
108
109
|
note: "Notes",
|
|
109
110
|
label: "Libell\xE9",
|
|
110
|
-
required: "Tous les champs requis doivent \xEAtre renseign\xE9s"
|
|
111
|
+
required: "Tous les champs requis doivent \xEAtre renseign\xE9s",
|
|
112
|
+
"not-valid": "Certains champs ne sont pas correctement remplis"
|
|
111
113
|
},
|
|
112
114
|
label: {
|
|
113
115
|
none: "Aucun",
|
|
@@ -182,7 +184,8 @@ var ru = {
|
|
|
182
184
|
relationship: "\u041E\u0442\u043D\u043E\u0448\u0435\u043D\u0438\u0435",
|
|
183
185
|
note: "\u0417\u0430\u043C\u0435\u0442\u043A\u0438",
|
|
184
186
|
label: "\u041C\u0435\u0442\u043A\u0430",
|
|
185
|
-
required: "\u0412\u0441\u0435 \u043E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u044B\u0435 \u043F\u043E\u043B\u044F \u0434\u043E\u043B\u0436\u043D\u044B \u0431\u044B\u0442\u044C \u0437\u0430\u043F\u043E\u043B\u043D\u0435\u043D\u044B"
|
|
187
|
+
required: "\u0412\u0441\u0435 \u043E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u044B\u0435 \u043F\u043E\u043B\u044F \u0434\u043E\u043B\u0436\u043D\u044B \u0431\u044B\u0442\u044C \u0437\u0430\u043F\u043E\u043B\u043D\u0435\u043D\u044B",
|
|
188
|
+
"not-valid": "\u041D\u0435\u043A\u043E\u0442\u043E\u0440\u044B\u0435 \u043F\u043E\u043B\u044F \u0437\u0430\u043F\u043E\u043B\u043D\u0435\u043D\u044B \u043D\u0435\u0432\u0435\u0440\u043D\u043E"
|
|
186
189
|
},
|
|
187
190
|
label: {
|
|
188
191
|
none: "\u041D\u0435\u0442",
|
|
@@ -257,7 +260,8 @@ var vi = {
|
|
|
257
260
|
relationship: "M\u1ED1i quan h\u1EC7",
|
|
258
261
|
note: "Ghi ch\xFA",
|
|
259
262
|
label: "Nh\xE3n",
|
|
260
|
-
required: "T\u1EA5t c\u1EA3 c\xE1c tr\u01B0\u1EDDng b\u1EAFt bu\u1ED9c ph\u1EA3i \u0111\u01B0\u1EE3c \u0111i\u1EC1n"
|
|
263
|
+
required: "T\u1EA5t c\u1EA3 c\xE1c tr\u01B0\u1EDDng b\u1EAFt bu\u1ED9c ph\u1EA3i \u0111\u01B0\u1EE3c \u0111i\u1EC1n",
|
|
264
|
+
"not-valid": "M\u1ED9t s\u1ED1 tr\u01B0\u1EDDng kh\xF4ng \u0111\u01B0\u1EE3c \u0111i\u1EC1n ch\xEDnh x\xE1c"
|
|
261
265
|
},
|
|
262
266
|
label: {
|
|
263
267
|
none: "Kh\xF4ng c\xF3",
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export default FieldInputLayout;
|
|
2
|
-
declare function FieldInputLayout({ attributes: { layout, icon, isSecondary, ...attributes }, contacts, showSecondaryFields, formProps }: {
|
|
2
|
+
declare function FieldInputLayout({ attributes: { layout, icon, isSecondary, validate, ...attributes }, contacts, showSecondaryFields, formProps }: {
|
|
3
3
|
attributes: {
|
|
4
4
|
[x: string]: any;
|
|
5
5
|
layout: any;
|
|
6
6
|
icon: any;
|
|
7
7
|
isSecondary: any;
|
|
8
|
+
validate: any;
|
|
8
9
|
};
|
|
9
10
|
contacts: any;
|
|
10
11
|
showSecondaryFields: any;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-ui-plus",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0",
|
|
4
4
|
"description": "Cozy-ui-plus is an extension of cozy-ui and provides components based on cozy-client",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
"react-dom": "^16 || ^17 || ^18",
|
|
75
75
|
"twake-i18n": ">=0.3.0"
|
|
76
76
|
},
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "053df29f6dfe606ecadd3f6668f0461bb1bd6021"
|
|
78
78
|
}
|
|
@@ -12,7 +12,8 @@ import { makeIsRequiredError } from './helpers'
|
|
|
12
12
|
import { locales } from './locales'
|
|
13
13
|
|
|
14
14
|
const FieldInputLayout = ({
|
|
15
|
-
|
|
15
|
+
// eslint-disable-next-line no-unused-vars
|
|
16
|
+
attributes: { layout, icon, isSecondary, validate, ...attributes }, // ⚠️ `layout` `icon` `isSecondary` `validate` here are removed from attributes to avoid DOM propagration
|
|
16
17
|
contacts,
|
|
17
18
|
showSecondaryFields,
|
|
18
19
|
formProps
|
|
@@ -50,19 +50,33 @@ export const makeIsRequiredError = (required, formProps) => {
|
|
|
50
50
|
*/
|
|
51
51
|
export const validateFields = (values, fields, t) => {
|
|
52
52
|
const errors = {}
|
|
53
|
-
const fieldsRequired = fields.filter(field => field.required)
|
|
54
53
|
const _values = getFirstValueIfArray(values)
|
|
55
54
|
|
|
56
|
-
|
|
57
|
-
if
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
55
|
+
fields.forEach(field => {
|
|
56
|
+
// test if required fields are empty
|
|
57
|
+
if (field.required) {
|
|
58
|
+
if (!get(_values, field.name)) {
|
|
59
|
+
errors[field.name] =
|
|
60
|
+
field.layout === 'array'
|
|
61
|
+
? [
|
|
62
|
+
{
|
|
63
|
+
[field.name]: t(
|
|
64
|
+
'Contacts.AddModal.ContactForm.fields.required'
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
: t('Contacts.AddModal.ContactForm.fields.required')
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// test if validate fn on field is verified
|
|
73
|
+
if (field.validate) {
|
|
74
|
+
const fieldValue = _values[field.name]
|
|
75
|
+
const isFieldValid = field.validate(fieldValue)
|
|
76
|
+
|
|
77
|
+
if (!isFieldValid) {
|
|
78
|
+
errors[field.name] = t('Contacts.AddModal.ContactForm.fields.not-valid')
|
|
79
|
+
}
|
|
66
80
|
}
|
|
67
81
|
})
|
|
68
82
|
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
} from './helpers'
|
|
15
15
|
import { locales } from './locales'
|
|
16
16
|
|
|
17
|
-
const t = x => get(locales.en, x)
|
|
17
|
+
const t = x => get(locales.en, x, x)
|
|
18
18
|
|
|
19
19
|
describe('makeCustomLabel', () => {
|
|
20
20
|
it('should return custom type and supported label', () => {
|
|
@@ -731,4 +731,13 @@ describe('validateFields', () => {
|
|
|
731
731
|
|
|
732
732
|
expect(res).toEqual({})
|
|
733
733
|
})
|
|
734
|
+
|
|
735
|
+
it('should return errors for not validated fields', () => {
|
|
736
|
+
const values = { mail: '0mymail@domain.com' }
|
|
737
|
+
const fields = [{ name: 'mail', validate: () => false }]
|
|
738
|
+
|
|
739
|
+
const res = validateFields(values, fields, t)
|
|
740
|
+
|
|
741
|
+
expect(res).toEqual({ mail: 'Some fields are not filled correctly' })
|
|
742
|
+
})
|
|
734
743
|
})
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
"relationship": "Relationship",
|
|
27
27
|
"note": "Notes",
|
|
28
28
|
"label": "Label",
|
|
29
|
-
"required": "All required fields must be filled in"
|
|
29
|
+
"required": "All required fields must be filled in",
|
|
30
|
+
"not-valid": "Some fields are not filled correctly"
|
|
30
31
|
},
|
|
31
32
|
"label": {
|
|
32
33
|
"none": "None",
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
"relationship": "Relation",
|
|
27
27
|
"note": "Notes",
|
|
28
28
|
"label": "Libellé",
|
|
29
|
-
"required": "Tous les champs requis doivent être renseignés"
|
|
29
|
+
"required": "Tous les champs requis doivent être renseignés",
|
|
30
|
+
"not-valid": "Certains champs ne sont pas correctement remplis"
|
|
30
31
|
},
|
|
31
32
|
"label": {
|
|
32
33
|
"none": "Aucun",
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
"relationship": "Отношение",
|
|
27
27
|
"note": "Заметки",
|
|
28
28
|
"label": "Метка",
|
|
29
|
-
"required": "Все обязательные поля должны быть заполнены"
|
|
29
|
+
"required": "Все обязательные поля должны быть заполнены",
|
|
30
|
+
"not-valid": "Некоторые поля заполнены неверно"
|
|
30
31
|
},
|
|
31
32
|
"label": {
|
|
32
33
|
"none": "Нет",
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
"relationship": "Mối quan hệ",
|
|
27
27
|
"note": "Ghi chú",
|
|
28
28
|
"label": "Nhãn",
|
|
29
|
-
"required": "Tất cả các trường bắt buộc phải được điền"
|
|
29
|
+
"required": "Tất cả các trường bắt buộc phải được điền",
|
|
30
|
+
"not-valid": "Một số trường không được điền chính xác"
|
|
30
31
|
},
|
|
31
32
|
"label": {
|
|
32
33
|
"none": "Không có",
|