@ukhomeoffice/cop-react-form-renderer 5.87.0 → 5.88.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.
@@ -62,7 +62,7 @@ var SummaryCardDetails = function SummaryCardDetails(_ref) {
62
62
  if (component.type === _models.ComponentTypes.CONTAINER) {
63
63
  var containerRows = (0, _getCYARowsForContainer.default)(childPage, component, entryData);
64
64
  rowIndex += 1;
65
- return /*#__PURE__*/_react.default.createElement("dl", {
65
+ return /*#__PURE__*/_react.default.createElement("div", {
66
66
  key: fieldId,
67
67
  className: classes('field'),
68
68
  style: {
@@ -84,7 +84,7 @@ var SummaryCardDetails = function SummaryCardDetails(_ref) {
84
84
  }), component, entryData[component.id]);
85
85
  rowIndex += 1;
86
86
  var collectionHeadingIndex = 0;
87
- return /*#__PURE__*/_react.default.createElement("dl", {
87
+ return /*#__PURE__*/_react.default.createElement("div", {
88
88
  key: fieldId,
89
89
  className: classes('field'),
90
90
  style: {
@@ -113,7 +113,7 @@ var SummaryCardDetails = function SummaryCardDetails(_ref) {
113
113
  }));
114
114
  }
115
115
  rowIndex += 1;
116
- return /*#__PURE__*/_react.default.createElement("dl", {
116
+ return /*#__PURE__*/_react.default.createElement("div", {
117
117
  key: fieldId,
118
118
  className: classes('field'),
119
119
  style: {
@@ -183,7 +183,7 @@ var SummaryCardDetails = function SummaryCardDetails(_ref) {
183
183
  className: classes('section')
184
184
  }, !hideChildSectionTitles && /*#__PURE__*/_react.default.createElement("h3", {
185
185
  className: classes('section-title')
186
- }, _utils.default.FormPage.getConditionalText(section.title, _objectSpread(_objectSpread({}, childPage.formData), entryData))), /*#__PURE__*/_react.default.createElement("div", {
186
+ }, _utils.default.FormPage.getConditionalText(section.title, _objectSpread(_objectSpread({}, childPage.formData), entryData))), /*#__PURE__*/_react.default.createElement("dl", {
187
187
  className: classes('section-content'),
188
188
  style: {
189
189
  '--dividers': columns.length - 1
@@ -15,14 +15,14 @@ var _mustBeShorterThan = _interopRequireDefault(require("./mustBeShorterThan"));
15
15
  var _mustBeGreaterThan = _interopRequireDefault(require("./mustBeGreaterThan"));
16
16
  var _mustBeLessThan = _interopRequireDefault(require("./mustBeLessThan"));
17
17
  var _mustBeNumbersOnly = _interopRequireDefault(require("./mustBeNumbersOnly"));
18
+ var _mustBeOneOf = _interopRequireDefault(require("./mustBeOneOf"));
18
19
  var _mustBeUniqueInCollection = _interopRequireDefault(require("./mustBeUniqueInCollection"));
19
20
  var _mustEnterAtLeastOne = _interopRequireDefault(require("./mustEnterAtLeastOne"));
20
21
  var _mustHaveLessThanDecimalPlaces = _interopRequireDefault(require("./mustHaveLessThanDecimalPlaces"));
21
22
  var _mustNotContainSql = _interopRequireDefault(require("./mustNotContainSql"));
22
23
  var _mustSelectOnlyOne = _interopRequireDefault(require("./mustSelectOnlyOne"));
23
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
- // Local imports
25
-
25
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } // Local imports
26
26
  var functions = {
27
27
  conditionallyRequired: _conditionallyRequired.default,
28
28
  mustBeAfter: _mustBeAfter.default,
@@ -34,6 +34,7 @@ var functions = {
34
34
  mustBeLessThan: _mustBeLessThan.default,
35
35
  mustBeLongerThan: _mustBeLongerThan.default,
36
36
  mustBeNumbersOnly: _mustBeNumbersOnly.default,
37
+ mustBeOneOf: _mustBeOneOf.default,
37
38
  mustBeShorterThan: _mustBeShorterThan.default,
38
39
  mustBeUniqueInCollection: _mustBeUniqueInCollection.default,
39
40
  mustEnterAtLeastOne: _mustEnterAtLeastOne.default,
@@ -43,8 +44,9 @@ var functions = {
43
44
  };
44
45
  var additionalValidation = function additionalValidation(value, config, component, formData) {
45
46
  var fn = functions[config.function];
47
+ var valueToValidate = _typeof(value) === 'object' ? value[config.objectValueToUse] : value;
46
48
  if (typeof fn === 'function') {
47
- return fn(value, config, component, formData) ? undefined : config.message;
49
+ return fn(valueToValidate, config, component, formData) ? undefined : config.message;
48
50
  }
49
51
  return undefined;
50
52
  };
@@ -58,6 +58,22 @@ describe('utils', function () {
58
58
  var VALUE = (0, _dayjs.default)().add(150, 'day').format(_utils.DATE_FORMAT);
59
59
  expect((0, _index.default)(COMPONENT, VALUE)).toEqual(undefined);
60
60
  });
61
+ it('should apply optional validators when the value is within an object', function () {
62
+ var COMPONENT = {
63
+ additionalValidation: [{
64
+ function: 'mustBeAfter',
65
+ value: 3,
66
+ unit: 'day',
67
+ objectValueToUse: "date",
68
+ message: 'Date must be more than 3 days in the future'
69
+ }]
70
+ };
71
+ var VALUE = {
72
+ testValue: "",
73
+ date: (0, _dayjs.default)().add(1, 'day').format(_utils.DATE_FORMAT)
74
+ };
75
+ expect((0, _index.default)(COMPONENT, VALUE)).toEqual('Date must be more than 3 days in the future');
76
+ });
61
77
  });
62
78
  });
63
79
  });
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ /**
8
+ * Function returns true if the string parameter is contained in the passed in array.
9
+ * @param {string} string - the string to check.
10
+ * @param {array} config.array - the array that the string will be checked against.
11
+ * @returns true if string is contained in config.array, false if not.
12
+ */
13
+ var mustBeOneOf = function mustBeOneOf(string, config) {
14
+ if (!string) {
15
+ // null, undefined and empty strings should be picked up by the required flag
16
+ // and not considered here as they would be valid for optional fields.
17
+ return true;
18
+ }
19
+ return config.array.includes(string);
20
+ };
21
+ var _default = exports.default = mustBeOneOf;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ var _mustBeOneOf = _interopRequireDefault(require("./mustBeOneOf"));
4
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
5
+ describe('utils', function () {
6
+ describe('Validate', function () {
7
+ describe('additional', function () {
8
+ describe('mustBeShorterThan', function () {
9
+ test('should return true given the string is in the array', function () {
10
+ var result = (0, _mustBeOneOf.default)('test2', {
11
+ array: ["test1", "test2", "test3", "test4"]
12
+ });
13
+ expect(result).toEqual(true);
14
+ });
15
+ test('should return false given the string is not in the array', function () {
16
+ var result = (0, _mustBeOneOf.default)('test5', {
17
+ array: ["test1", "test2", "test3", "test4"]
18
+ });
19
+ expect(result).toEqual(false);
20
+ });
21
+ test('should return false given the array is empty', function () {
22
+ var result = (0, _mustBeOneOf.default)('test1', {
23
+ array: []
24
+ });
25
+ expect(result).toEqual(false);
26
+ });
27
+ test('should return false when only the partial string is in the array', function () {
28
+ var result = (0, _mustBeOneOf.default)('test', {
29
+ array: ["test1", "test2", "test3", "test4"]
30
+ });
31
+ expect(result).toEqual(false);
32
+ });
33
+ });
34
+ });
35
+ });
36
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "5.87.0",
3
+ "version": "5.88.2",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",
@@ -16,7 +16,7 @@
16
16
  "post-compile": "rimraf dist/*.test.* dist/**/*.test.* dist/**/*.stories.* dist/docs dist/assets"
17
17
  },
18
18
  "dependencies": {
19
- "@ukhomeoffice/cop-react-components": "3.23.0",
19
+ "@ukhomeoffice/cop-react-components": "3.24.0",
20
20
  "axios": "^0.23.0",
21
21
  "dayjs": "^1.11.0",
22
22
  "govuk-frontend": "^4.3.1",