@ukhomeoffice/cop-react-form-renderer 3.0.1 → 3.0.2
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.
|
@@ -15,7 +15,14 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
15
15
|
|
|
16
16
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Validates all of the items within a collection.
|
|
20
|
+
* @param {object} collection The collection to validate.
|
|
21
|
+
* @param {object} items The data items in the collection.
|
|
22
|
+
* @param {object} formData The data at the top level of the form.
|
|
23
|
+
* @returns Errors for all components for all items within the collection.
|
|
24
|
+
*/
|
|
25
|
+
var validateCollection = function validateCollection(collection, items, formData) {
|
|
19
26
|
var errors = [];
|
|
20
27
|
|
|
21
28
|
if (collection && Array.isArray(collection.item) && Array.isArray(items)) {
|
|
@@ -29,7 +36,7 @@ var validateCollection = function validateCollection(collection, items) {
|
|
|
29
36
|
});
|
|
30
37
|
})
|
|
31
38
|
};
|
|
32
|
-
errors.push((0, _validateContainer.default)(container, item));
|
|
39
|
+
errors.push((0, _validateContainer.default)(container, item, formData));
|
|
33
40
|
});
|
|
34
41
|
}
|
|
35
42
|
|
|
@@ -32,25 +32,27 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
|
|
|
32
32
|
/**
|
|
33
33
|
* Validates a single component.
|
|
34
34
|
* @param {object} component The component to validate.
|
|
35
|
-
* @param {object}
|
|
35
|
+
* @param {object} outerData The data to use that holds this component's value.
|
|
36
|
+
* @param {object} formData The data at the top level of the form.
|
|
36
37
|
* @returns The first encountered error with the component.
|
|
37
38
|
*/
|
|
38
|
-
var validateComponent = function validateComponent(component, formData) {
|
|
39
|
+
var validateComponent = function validateComponent(component, outerData, formData) {
|
|
39
40
|
var _component$data$optio;
|
|
40
41
|
|
|
41
|
-
|
|
42
|
+
var fd = formData || outerData;
|
|
43
|
+
|
|
44
|
+
if (!(0, _showComponent.default)(component, fd)) {
|
|
42
45
|
return undefined;
|
|
43
46
|
}
|
|
44
47
|
|
|
45
|
-
var error = undefined;
|
|
46
|
-
var nestedId = undefined;
|
|
47
|
-
var propertiesInError = undefined;
|
|
48
|
-
var data = formData && _typeof(formData) === 'object' ? formData : {};
|
|
49
|
-
|
|
50
48
|
if (component.type === _models.ComponentTypes.CONTAINER) {
|
|
51
|
-
return (0, _validateContainer.default)(component,
|
|
49
|
+
return (0, _validateContainer.default)(component, outerData, fd);
|
|
52
50
|
}
|
|
53
51
|
|
|
52
|
+
var error = undefined;
|
|
53
|
+
var nestedId = undefined;
|
|
54
|
+
var properties = undefined;
|
|
55
|
+
var data = outerData && _typeof(outerData) === 'object' ? outerData : {};
|
|
54
56
|
var value = data[component.fieldId];
|
|
55
57
|
|
|
56
58
|
if (component.required) {
|
|
@@ -60,7 +62,7 @@ var validateComponent = function validateComponent(component, formData) {
|
|
|
60
62
|
if (!error) {
|
|
61
63
|
switch (component.type) {
|
|
62
64
|
case _models.ComponentTypes.COLLECTION:
|
|
63
|
-
return (0, _validateCollection.default)(component, value);
|
|
65
|
+
return (0, _validateCollection.default)(component, value, fd);
|
|
64
66
|
|
|
65
67
|
case _models.ComponentTypes.EMAIL:
|
|
66
68
|
error = (0, _validateEmail.default)(value, component.label);
|
|
@@ -74,7 +76,7 @@ var validateComponent = function validateComponent(component, formData) {
|
|
|
74
76
|
message = _validator.message,
|
|
75
77
|
propsInError = _validator.propsInError;
|
|
76
78
|
|
|
77
|
-
|
|
79
|
+
properties = propsInError;
|
|
78
80
|
error = message;
|
|
79
81
|
break;
|
|
80
82
|
|
|
@@ -83,12 +85,10 @@ var validateComponent = function validateComponent(component, formData) {
|
|
|
83
85
|
var nestedError;
|
|
84
86
|
|
|
85
87
|
if (option.nested && option.nested.shown) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
nestedError = validateComponent(option.nested, formData);
|
|
89
|
-
error = (_nestedError = nestedError) === null || _nestedError === void 0 ? void 0 : _nestedError.error;
|
|
88
|
+
nestedError = validateComponent(option.nested, outerData, fd);
|
|
90
89
|
|
|
91
90
|
if (nestedError) {
|
|
91
|
+
error = nestedError.error;
|
|
92
92
|
nestedId = nestedError.id;
|
|
93
93
|
}
|
|
94
94
|
}
|
|
@@ -109,7 +109,7 @@ var validateComponent = function validateComponent(component, formData) {
|
|
|
109
109
|
error = (0, _additional.default)(component, value);
|
|
110
110
|
|
|
111
111
|
if (component.type === _models.ComponentTypes.DATE && error) {
|
|
112
|
-
|
|
112
|
+
properties = {
|
|
113
113
|
day: true,
|
|
114
114
|
month: true,
|
|
115
115
|
year: true
|
|
@@ -122,7 +122,7 @@ var validateComponent = function validateComponent(component, formData) {
|
|
|
122
122
|
return {
|
|
123
123
|
id: nestedId || component.full_path || component.id,
|
|
124
124
|
error: error,
|
|
125
|
-
properties:
|
|
125
|
+
properties: properties
|
|
126
126
|
};
|
|
127
127
|
}
|
|
128
128
|
|
|
@@ -10,13 +10,22 @@ var _validateComponent = _interopRequireDefault(require("./validateComponent"));
|
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
11
|
|
|
12
12
|
// Local imports
|
|
13
|
-
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Validates all components within a container.
|
|
16
|
+
* @param {object} container The container to validate.
|
|
17
|
+
* @param {object} outerData The data to use that holds this component's value.
|
|
18
|
+
* @param {object} formData The data at the top level of the form.
|
|
19
|
+
* @returns Errors for all components within the container.
|
|
20
|
+
*/
|
|
21
|
+
var validateContainer = function validateContainer(container, outerData, formData) {
|
|
22
|
+
var fd = formData || outerData;
|
|
14
23
|
var errors = [];
|
|
15
24
|
|
|
16
25
|
if (container && Array.isArray(container.components)) {
|
|
17
|
-
var
|
|
26
|
+
var containerData = outerData && container.fieldId ? outerData[container.fieldId] : outerData;
|
|
18
27
|
container.components.forEach(function (component) {
|
|
19
|
-
errors.push((0, _validateComponent.default)(component, fd));
|
|
28
|
+
errors.push((0, _validateComponent.default)(component, containerData, fd));
|
|
20
29
|
});
|
|
21
30
|
}
|
|
22
31
|
|
|
@@ -21,7 +21,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
21
21
|
var validatePage = function validatePage(page) {
|
|
22
22
|
if ((0, _showFormPage.default)(page, page.formData) && Array.isArray(page.components)) {
|
|
23
23
|
return page.components.reduce(function (errors, component) {
|
|
24
|
-
return errors.concat((0, _validateComponent.default)(component, page.formData));
|
|
24
|
+
return errors.concat((0, _validateComponent.default)(component, page.formData, page.formData));
|
|
25
25
|
}, []).filter(function (e) {
|
|
26
26
|
return !!e;
|
|
27
27
|
}).flat();
|