@ukhomeoffice/cop-react-form-renderer 5.88.2 → 5.88.6

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.
@@ -89,7 +89,7 @@ var FormComponent = function FormComponent(_ref) {
89
89
  };
90
90
  (0, _react.useEffect)(function () {
91
91
  var defaultValue = _utils.default.Component.defaultValue(component, formData);
92
- if (!value && defaultValue) {
92
+ if (!value && !(formData !== null && formData !== void 0 && formData[component.fieldId]) && defaultValue) {
93
93
  if (typeof onComponentChange === 'function') {
94
94
  onComponentChange({
95
95
  target: {
@@ -22,7 +22,8 @@ var _mustHaveLessThanDecimalPlaces = _interopRequireDefault(require("./mustHaveL
22
22
  var _mustNotContainSql = _interopRequireDefault(require("./mustNotContainSql"));
23
23
  var _mustSelectOnlyOne = _interopRequireDefault(require("./mustSelectOnlyOne"));
24
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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
25
+ // Local imports
26
+
26
27
  var functions = {
27
28
  conditionallyRequired: _conditionallyRequired.default,
28
29
  mustBeAfter: _mustBeAfter.default,
@@ -44,7 +45,7 @@ var functions = {
44
45
  };
45
46
  var additionalValidation = function additionalValidation(value, config, component, formData) {
46
47
  var fn = functions[config.function];
47
- var valueToValidate = _typeof(value) === 'object' ? value[config.objectValueToUse] : value;
48
+ var valueToValidate = config.objectValueToUse ? value[config.objectValueToUse] : value;
48
49
  if (typeof fn === 'function') {
49
50
  return fn(valueToValidate, config, component, formData) ? undefined : config.message;
50
51
  }
@@ -58,6 +58,56 @@ 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 that fail when the value is an object', function () {
62
+ var COMPONENT = {
63
+ fieldId: 'container',
64
+ components: [{
65
+ id: 'eventDate',
66
+ fieldId: 'eventDate'
67
+ }, {
68
+ id: 'eventTime',
69
+ fieldId: 'eventTime'
70
+ }],
71
+ additionalValidation: [{
72
+ function: 'mustBeEarlierDateTime',
73
+ date: 'eventDate',
74
+ time: 'eventTime',
75
+ message: 'The date and time cannot be in the future'
76
+ }]
77
+ };
78
+ var VALUE = {
79
+ container: {
80
+ eventDate: '01-07-4024',
81
+ eventTime: '1:1'
82
+ }
83
+ };
84
+ expect((0, _index.default)(COMPONENT, VALUE)).toEqual('The date and time cannot be in the future');
85
+ });
86
+ it('should apply optional validators that pass when the value is an object', function () {
87
+ var COMPONENT = {
88
+ fieldId: 'container',
89
+ components: [{
90
+ id: 'eventDate',
91
+ fieldId: 'eventDate'
92
+ }, {
93
+ id: 'eventTime',
94
+ fieldId: 'eventTime'
95
+ }],
96
+ additionalValidation: [{
97
+ function: 'mustBeEarlierDateTime',
98
+ date: 'eventDate',
99
+ time: 'eventTime',
100
+ message: 'The date and time cannot be in the future'
101
+ }]
102
+ };
103
+ var VALUE = {
104
+ container: {
105
+ eventDate: '01-07-1024',
106
+ eventTime: '1:1'
107
+ }
108
+ };
109
+ expect((0, _index.default)(COMPONENT, VALUE)).toEqual(undefined);
110
+ });
61
111
  it('should apply optional validators when the value is within an object', function () {
62
112
  var COMPONENT = {
63
113
  additionalValidation: [{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "5.88.2",
3
+ "version": "5.88.6",
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.24.0",
19
+ "@ukhomeoffice/cop-react-components": "3.24.1",
20
20
  "axios": "^0.23.0",
21
21
  "dayjs": "^1.11.0",
22
22
  "govuk-frontend": "^4.3.1",
@@ -101,4 +101,4 @@
101
101
  "last 1 safari version"
102
102
  ]
103
103
  }
104
- }
104
+ }