@ukhomeoffice/cop-react-form-renderer 4.75.0 → 4.76.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.
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
7
8
|
var _validateContainer = _interopRequireDefault(require("./validateContainer"));
|
|
8
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
10
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
@@ -23,13 +24,24 @@ var validateCollection = function validateCollection(collection, items, formData
|
|
|
23
24
|
var errors = [];
|
|
24
25
|
if (collection && Array.isArray(collection.item) && Array.isArray(items)) {
|
|
25
26
|
items.forEach(function (item, index) {
|
|
27
|
+
var labelCount = (collection.countOffset || 0) + index + 1;
|
|
26
28
|
var fullPath = "".concat(collection.full_path || collection.fieldId, "[").concat(index, "]");
|
|
27
29
|
var container = {
|
|
28
30
|
full_path: fullPath,
|
|
29
31
|
components: collection.item.map(function (component) {
|
|
30
|
-
|
|
32
|
+
var newComponent = _objectSpread(_objectSpread({}, component), {}, {
|
|
31
33
|
full_path: "".concat(fullPath, ".").concat(component.fieldId)
|
|
32
34
|
});
|
|
35
|
+
if (Array.isArray(component.custom_errors)) {
|
|
36
|
+
newComponent.custom_errors = component.custom_errors.map(function (error) {
|
|
37
|
+
return _objectSpread(_objectSpread({}, error), {}, {
|
|
38
|
+
message: _copReactComponents.Utils.interpolateString(error.message, {
|
|
39
|
+
index: labelCount
|
|
40
|
+
})
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return newComponent;
|
|
33
45
|
})
|
|
34
46
|
};
|
|
35
47
|
errors.push((0, _validateContainer.default)(container, item, formData));
|
|
@@ -69,4 +69,21 @@ describe('utils.Validate.Collection', function () {
|
|
|
69
69
|
error: "Enter ".concat(EMAIL_LABEL.toLowerCase(), " in the correct format, like jane.doe@homeoffice.gov.uk")
|
|
70
70
|
}]);
|
|
71
71
|
});
|
|
72
|
+
it('should correctly interpolate error messages using collection\'s index', function () {
|
|
73
|
+
var ID = 'container';
|
|
74
|
+
var LABEL = 'field';
|
|
75
|
+
var TYPE = 'autocomplete';
|
|
76
|
+
var ITEM = setup(ID, TYPE, LABEL, true, []);
|
|
77
|
+
ITEM.custom_errors = [{
|
|
78
|
+
"type": "required",
|
|
79
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
80
|
+
"message": "Test to check that ${index} is 1"
|
|
81
|
+
}];
|
|
82
|
+
var COLLECTION = setup(ID, _models.ComponentTypes.CONTAINER, LABEL, false, [ITEM]);
|
|
83
|
+
COLLECTION.countOffset = 0;
|
|
84
|
+
expect((0, _validateCollection.default)(COLLECTION, ITEM.custom_errors)).toEqual([{
|
|
85
|
+
error: "Test to check that 1 is 1",
|
|
86
|
+
id: "".concat(ID, "[0].").concat(COLLECTION.type)
|
|
87
|
+
}]);
|
|
88
|
+
});
|
|
72
89
|
});
|