@ukhomeoffice/cop-react-form-renderer 4.87.0 → 4.88.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.
|
@@ -22,7 +22,6 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
|
|
|
22
22
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
23
23
|
var LIST_CLASS = 'govuk-list';
|
|
24
24
|
var BODY_CLASS = 'govuk-body';
|
|
25
|
-
var INPUT_CLASS = 'govuk-input';
|
|
26
25
|
|
|
27
26
|
/**
|
|
28
27
|
* Separate function for each component type for the sake of
|
|
@@ -159,13 +158,7 @@ var getTextArea = function getTextArea(config) {
|
|
|
159
158
|
};
|
|
160
159
|
var getTextInput = function getTextInput(config) {
|
|
161
160
|
var attrs = (0, _cleanAttributes.default)(config);
|
|
162
|
-
|
|
163
|
-
var className = attrs.fluidWidth ? [attrs.fluidWidth] : undefined;
|
|
164
|
-
return /*#__PURE__*/_react.default.createElement(_copReactComponents.TextInput, _extends({}, attrs, {
|
|
165
|
-
classBlock: INPUT_CLASS,
|
|
166
|
-
classModifiers: classModifiers,
|
|
167
|
-
className: className
|
|
168
|
-
}));
|
|
161
|
+
return /*#__PURE__*/_react.default.createElement(_copReactComponents.TextInput, attrs);
|
|
169
162
|
};
|
|
170
163
|
var getTime = function getTime(config) {
|
|
171
164
|
var attrs = (0, _cleanAttributes.default)(config);
|
|
@@ -32,10 +32,10 @@ var validateCollection = function validateCollection(collection, items, formData
|
|
|
32
32
|
var newComponent = _objectSpread(_objectSpread({}, component), {}, {
|
|
33
33
|
full_path: "".concat(fullPath, ".").concat(component.fieldId)
|
|
34
34
|
});
|
|
35
|
-
if (Array.isArray(component.custom_errors)) {
|
|
35
|
+
if (component.custom_errors && Array.isArray(component.custom_errors)) {
|
|
36
36
|
newComponent.custom_errors = component.custom_errors.map(function (error) {
|
|
37
37
|
return _objectSpread(_objectSpread({}, error), {}, {
|
|
38
|
-
message: _copReactComponents.Utils.interpolateString(error.message, {
|
|
38
|
+
message: _copReactComponents.Utils.interpolateString(index === 0 && error.firstOnlyMessage ? error.firstOnlyMessage : error.message, {
|
|
39
39
|
index: labelCount
|
|
40
40
|
})
|
|
41
41
|
});
|
|
@@ -86,4 +86,40 @@ describe('utils.Validate.Collection', function () {
|
|
|
86
86
|
id: "".concat(ID, "[0].").concat(COLLECTION.type)
|
|
87
87
|
}]);
|
|
88
88
|
});
|
|
89
|
+
it('should correctly display firstOnlyMessage error message', function () {
|
|
90
|
+
var ID = 'container';
|
|
91
|
+
var LABEL = 'field';
|
|
92
|
+
var TYPE = 'autocomplete';
|
|
93
|
+
var ITEM = setup(ID, TYPE, LABEL, true, []);
|
|
94
|
+
ITEM.custom_errors = [{
|
|
95
|
+
"type": "required",
|
|
96
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
97
|
+
"message": "Test to check that ${index} is 1",
|
|
98
|
+
"firstOnlyMessage": "Test for first message"
|
|
99
|
+
}];
|
|
100
|
+
var COLLECTION = setup(ID, _models.ComponentTypes.CONTAINER, LABEL, false, [ITEM]);
|
|
101
|
+
COLLECTION.countOffset = 0;
|
|
102
|
+
expect((0, _validateCollection.default)(COLLECTION, ITEM.custom_errors)).toEqual([{
|
|
103
|
+
error: "Test for first message",
|
|
104
|
+
id: "".concat(ID, "[0].").concat(COLLECTION.type)
|
|
105
|
+
}]);
|
|
106
|
+
});
|
|
107
|
+
it('should correctly display message if firstOnlyMessage is undefined', function () {
|
|
108
|
+
var ID = 'container';
|
|
109
|
+
var LABEL = 'field';
|
|
110
|
+
var TYPE = 'autocomplete';
|
|
111
|
+
var ITEM = setup(ID, TYPE, LABEL, true, []);
|
|
112
|
+
ITEM.custom_errors = [{
|
|
113
|
+
"type": "required",
|
|
114
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
115
|
+
"message": "Test to check that ${index} is 1",
|
|
116
|
+
"firstOnlyMessage": undefined
|
|
117
|
+
}];
|
|
118
|
+
var COLLECTION = setup(ID, _models.ComponentTypes.CONTAINER, LABEL, false, [ITEM]);
|
|
119
|
+
COLLECTION.countOffset = 0;
|
|
120
|
+
expect((0, _validateCollection.default)(COLLECTION, ITEM.custom_errors)).toEqual([{
|
|
121
|
+
error: "Test to check that 1 is 1",
|
|
122
|
+
id: "".concat(ID, "[0].").concat(COLLECTION.type)
|
|
123
|
+
}]);
|
|
124
|
+
});
|
|
89
125
|
});
|