@ukhomeoffice/cop-react-form-renderer 4.32.2 → 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.
- package/dist/components/FormRenderer/FormRenderer.js +8 -4
- package/dist/utils/CollectionPage/mergeCollectionPages.test.js +6 -6
- package/dist/utils/Component/addShowWhen.js +6 -2
- package/dist/utils/Component/addShowWhen.test.js +100 -1
- package/dist/utils/FormPage/getPageActions.js +0 -6
- package/package.json +1 -1
|
@@ -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
|
-
|
|
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
|
|
551
|
-
var canSubmit = shouldValidate ? _helpers.default.canCYASubmit(currentTask.fullPages, validate.pages) : true;
|
|
553
|
+
var _shouldValidate = !(action.hasOwnProperty('validate') && !action.validate);
|
|
552
554
|
|
|
553
|
-
|
|
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
|
|
@@ -174,26 +174,26 @@ describe('utils.CollectionPage.mergeCollectionPages', function () {
|
|
|
174
174
|
},
|
|
175
175
|
components: [{
|
|
176
176
|
type: 'text',
|
|
177
|
-
show_when:
|
|
177
|
+
show_when: {
|
|
178
178
|
field: 'field',
|
|
179
179
|
op: '=',
|
|
180
180
|
value: 'value'
|
|
181
|
-
}
|
|
181
|
+
}
|
|
182
182
|
}, {
|
|
183
183
|
type: 'container',
|
|
184
184
|
components: [{
|
|
185
185
|
type: 'date',
|
|
186
|
-
show_when:
|
|
186
|
+
show_when: {
|
|
187
187
|
field: 'field',
|
|
188
188
|
op: '=',
|
|
189
189
|
value: 'otherValue'
|
|
190
|
-
}
|
|
190
|
+
}
|
|
191
191
|
}],
|
|
192
|
-
show_when:
|
|
192
|
+
show_when: {
|
|
193
193
|
field: 'field',
|
|
194
194
|
op: '=',
|
|
195
195
|
value: 'otherValue'
|
|
196
|
-
}
|
|
196
|
+
}
|
|
197
197
|
}],
|
|
198
198
|
formData: {}
|
|
199
199
|
});
|
|
@@ -34,9 +34,13 @@ var addShowWhen = function addShowWhen(component, condition) {
|
|
|
34
34
|
var result = _objectSpread({}, component);
|
|
35
35
|
|
|
36
36
|
if (result.show_when) {
|
|
37
|
-
|
|
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
|
-
result.show_when = condition
|
|
43
|
+
result.show_when = condition;
|
|
40
44
|
}
|
|
41
45
|
|
|
42
46
|
return result;
|
|
@@ -44,7 +44,26 @@ describe('utils.Component.addShowWhen', function () {
|
|
|
44
44
|
var result = (0, _addShowWhen.default)(COMPONENT, NEW_SHOW_WHEN);
|
|
45
45
|
expect(result).toEqual({
|
|
46
46
|
alpha: 'bravo',
|
|
47
|
-
show_when:
|
|
47
|
+
show_when: NEW_SHOW_WHEN
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
it('should add the array type show_when to a component with no existing show_whens', function () {
|
|
51
|
+
var NEW_ARRAY_SHOW_WHEN = [{
|
|
52
|
+
field: 'abc',
|
|
53
|
+
op: '=',
|
|
54
|
+
value: 'bcd'
|
|
55
|
+
}, {
|
|
56
|
+
field: 'cde',
|
|
57
|
+
op: '=',
|
|
58
|
+
value: 'efg'
|
|
59
|
+
}];
|
|
60
|
+
var COMPONENT = {
|
|
61
|
+
alpha: 'bravo'
|
|
62
|
+
};
|
|
63
|
+
var result = (0, _addShowWhen.default)(COMPONENT, NEW_ARRAY_SHOW_WHEN);
|
|
64
|
+
expect(result).toEqual({
|
|
65
|
+
alpha: 'bravo',
|
|
66
|
+
show_when: NEW_ARRAY_SHOW_WHEN
|
|
48
67
|
});
|
|
49
68
|
});
|
|
50
69
|
it('should add the show_when to a component with a single show_when', function () {
|
|
@@ -115,4 +134,84 @@ describe('utils.Component.addShowWhen', function () {
|
|
|
115
134
|
show_when: SHOW_WHEN_OR
|
|
116
135
|
});
|
|
117
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
|
+
});
|
|
118
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
|
|