@ukhomeoffice/cop-react-form-renderer 4.32.3 → 4.33.1

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.
@@ -509,7 +509,10 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
509
509
  }
510
510
 
511
511
  if (action.type === _models.PageAction.TYPES.SAVE_AND_CONTINUE && hub === _models.HubFormats.TASK) {
512
- if (_helpers.default.canCYASubmit(currentTask.fullPages, validate.pages)) {
512
+ var shouldValidate = !(action.hasOwnProperty('validate') && !action.validate);
513
+ var canSubmit = shouldValidate ? _helpers.default.canCYASubmit(currentTask.fullPages, validate.pages) : true;
514
+
515
+ if (canSubmit) {
513
516
  var _submissionData = _utils.default.Format.form({
514
517
  pages: pages,
515
518
  components: components
@@ -547,10 +550,11 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
547
550
  }
548
551
 
549
552
  if (action.type === _models.PageAction.TYPES.SAVE_AND_RETURN) {
550
- var shouldValidate = !(action.hasOwnProperty('validate') && !action.validate);
551
- var canSubmit = shouldValidate ? _helpers.default.canCYASubmit(currentTask.fullPages, validate.pages) : true;
553
+ var _shouldValidate = !(action.hasOwnProperty('validate') && !action.validate);
552
554
 
553
- if (canSubmit) {
555
+ var _canSubmit = _shouldValidate ? _helpers.default.canCYASubmit(currentTask.fullPages, validate.pages) : true;
556
+
557
+ if (_canSubmit) {
554
558
  var _submissionData3 = _utils.default.Format.form({
555
559
  pages: pages,
556
560
  components: components
@@ -34,7 +34,11 @@ var addShowWhen = function addShowWhen(component, condition) {
34
34
  var result = _objectSpread({}, component);
35
35
 
36
36
  if (result.show_when) {
37
- result.show_when = Array.isArray(result.show_when) ? [].concat(result.show_when, [_objectSpread({}, condition)]) : [result.show_when, _objectSpread({}, condition)];
37
+ if (Array.isArray(condition)) {
38
+ result.show_when = Array.isArray(result.show_when) ? [].concat(condition, result.show_when) : [].concat(condition, [result.show_when]);
39
+ } else {
40
+ result.show_when = Array.isArray(result.show_when) ? [].concat(result.show_when, [condition]) : [result.show_when, condition];
41
+ }
38
42
  } else {
39
43
  result.show_when = condition;
40
44
  }
@@ -61,7 +61,6 @@ describe('utils.Component.addShowWhen', function () {
61
61
  alpha: 'bravo'
62
62
  };
63
63
  var result = (0, _addShowWhen.default)(COMPONENT, NEW_ARRAY_SHOW_WHEN);
64
- console.log(result);
65
64
  expect(result).toEqual({
66
65
  alpha: 'bravo',
67
66
  show_when: NEW_ARRAY_SHOW_WHEN
@@ -135,4 +134,84 @@ describe('utils.Component.addShowWhen', function () {
135
134
  show_when: SHOW_WHEN_OR
136
135
  });
137
136
  });
137
+ it('should add an array of show_whens to a component with an array of show_whens', function () {
138
+ var NEW_ARRAY_SHOW_WHEN = [{
139
+ field: 'hij',
140
+ op: '=',
141
+ value: 'klm'
142
+ }, {
143
+ field: 'nop',
144
+ op: '=',
145
+ value: 'qrs'
146
+ }];
147
+ var COMPONENT = {
148
+ alpha: 'bravo',
149
+ show_when: [{
150
+ field: 'abc',
151
+ op: '=',
152
+ value: 'bcd'
153
+ }, {
154
+ field: 'cde',
155
+ op: '=',
156
+ value: 'efg'
157
+ }]
158
+ };
159
+ var result = (0, _addShowWhen.default)(COMPONENT, NEW_ARRAY_SHOW_WHEN);
160
+ expect(result).toEqual({
161
+ alpha: 'bravo',
162
+ show_when: [{
163
+ field: 'hij',
164
+ op: '=',
165
+ value: 'klm'
166
+ }, {
167
+ field: 'nop',
168
+ op: '=',
169
+ value: 'qrs'
170
+ }, {
171
+ field: 'abc',
172
+ op: '=',
173
+ value: 'bcd'
174
+ }, {
175
+ field: 'cde',
176
+ op: '=',
177
+ value: 'efg'
178
+ }]
179
+ });
180
+ });
181
+ it('should add an array of show_whens to a component with a single show_when', function () {
182
+ var NEW_ARRAY_SHOW_WHEN = [{
183
+ field: 'hij',
184
+ op: '=',
185
+ value: 'klm'
186
+ }, {
187
+ field: 'nop',
188
+ op: '=',
189
+ value: 'qrs'
190
+ }];
191
+ var COMPONENT = {
192
+ alpha: 'bravo',
193
+ show_when: {
194
+ field: 'abc',
195
+ op: '=',
196
+ value: 'bcd'
197
+ }
198
+ };
199
+ var result = (0, _addShowWhen.default)(COMPONENT, NEW_ARRAY_SHOW_WHEN);
200
+ expect(result).toEqual({
201
+ alpha: 'bravo',
202
+ show_when: [{
203
+ field: 'hij',
204
+ op: '=',
205
+ value: 'klm'
206
+ }, {
207
+ field: 'nop',
208
+ op: '=',
209
+ value: 'qrs'
210
+ }, {
211
+ field: 'abc',
212
+ op: '=',
213
+ value: 'bcd'
214
+ }]
215
+ });
216
+ });
138
217
  });
@@ -50,12 +50,6 @@ var getPageActions = function getPageActions(page) {
50
50
  }
51
51
 
52
52
  if (a && _typeof(a) === 'object') {
53
- var _PageAction$DEFAULTS$;
54
-
55
- if ((_PageAction$DEFAULTS$ = _models.PageAction.DEFAULTS[a.type]) !== null && _PageAction$DEFAULTS$ !== void 0 && _PageAction$DEFAULTS$.validate) {
56
- a.validate = true;
57
- }
58
-
59
53
  return standardiseAction(a);
60
54
  }
61
55
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "4.32.3",
3
+ "version": "4.33.1",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",