@ukhomeoffice/cop-react-form-renderer 4.28.0 → 4.29.0-beta
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/CheckYourAnswers/CheckYourAnswers.js +23 -5
- package/dist/components/CollectionPage/CollectionPage.test.js +9 -9
- package/dist/components/FormComponent/Collection.test.js +7 -7
- package/dist/components/FormComponent/Container.test.js +14 -14
- package/dist/components/FormComponent/FormComponent.test.js +6 -6
- package/dist/components/FormPage/FormPage.js +6 -1
- package/dist/components/FormPage/FormPage.test.js +8 -8
- package/dist/components/FormRenderer/FormRenderer.js +64 -7
- package/dist/components/FormRenderer/FormRenderer.test.js +71 -13
- package/dist/components/FormRenderer/handlers/navigate.js +2 -2
- package/dist/json/multiQuestionTaskList.json +275 -0
- package/dist/json/multiQuestionTaskListData.json +39 -0
- package/dist/models/PageAction.js +7 -1
- package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +4 -3
- package/dist/utils/Component/getComponentTests/getComponent.calculation.test.js +2 -2
- package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +4 -3
- package/dist/utils/Component/getComponentTests/getComponent.date.test.js +7 -7
- package/dist/utils/Component/getComponentTests/getComponent.email.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.file.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +11 -11
- package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.select.test.js +1 -7
- package/dist/utils/Component/getComponentTests/getComponent.text.test.js +3 -3
- package/dist/utils/Component/getComponentTests/getComponent.textarea.test.js +1 -1
- package/dist/utils/Component/getComponentTests/getComponent.time.test.js +4 -4
- package/dist/utils/Validate/validateComponent.js +3 -2
- package/dist/utils/Validate/validateEmail.js +9 -1
- package/dist/utils/Validate/validateEmail.test.js +8 -0
- package/package.json +2 -2
|
@@ -69,7 +69,9 @@ var CheckYourAnswers = function CheckYourAnswers(_ref) {
|
|
|
69
69
|
noChangeAction = _ref.noChangeAction,
|
|
70
70
|
groups = _ref.groups,
|
|
71
71
|
sections = _ref.sections,
|
|
72
|
-
type = _ref.type
|
|
72
|
+
type = _ref.type,
|
|
73
|
+
cysa = _ref.cysa,
|
|
74
|
+
currentPage = _ref.currentPage;
|
|
73
75
|
|
|
74
76
|
var _useState = (0, _react.useState)([]),
|
|
75
77
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -86,7 +88,7 @@ var CheckYourAnswers = function CheckYourAnswers(_ref) {
|
|
|
86
88
|
|
|
87
89
|
(0, _react.useEffect)(function () {
|
|
88
90
|
var getRows = function getRows(page, pageIndex) {
|
|
89
|
-
var rows = _utils.default.CheckYourAnswers.getRows(page, onRowAction);
|
|
91
|
+
var rows = _utils.default.CheckYourAnswers.getRows(page, onRowAction, currentPage);
|
|
90
92
|
|
|
91
93
|
return rows.map(function (row, index) {
|
|
92
94
|
return _objectSpread(_objectSpread({}, row), {}, {
|
|
@@ -109,8 +111,23 @@ var CheckYourAnswers = function CheckYourAnswers(_ref) {
|
|
|
109
111
|
}).filter(function (p) {
|
|
110
112
|
return !!p;
|
|
111
113
|
});
|
|
112
|
-
|
|
113
|
-
|
|
114
|
+
|
|
115
|
+
if (cysa) {
|
|
116
|
+
var indexOfCurrentPage = pagesWithRows.map(function (object) {
|
|
117
|
+
return object.id;
|
|
118
|
+
}).indexOf(currentPage);
|
|
119
|
+
|
|
120
|
+
if (indexOfCurrentPage === 0) {
|
|
121
|
+
setPages(pagesWithRows.slice(0, 1));
|
|
122
|
+
} else {
|
|
123
|
+
setPages(pagesWithRows.slice(0, indexOfCurrentPage));
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
setPages(pagesWithRows);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
;
|
|
130
|
+
}, [_pages, onRowAction, setPages, currentPage, cysa]);
|
|
114
131
|
var listMarginBottom = hide_page_titles ? 0 : DEFAULT_MARGIN_BOTTOM;
|
|
115
132
|
|
|
116
133
|
var isLastPage = function isLastPage(index) {
|
|
@@ -144,11 +161,12 @@ var CheckYourAnswers = function CheckYourAnswers(_ref) {
|
|
|
144
161
|
return groupAnswer;
|
|
145
162
|
};
|
|
146
163
|
|
|
164
|
+
var cysaTitle = 'Check your saved answers';
|
|
147
165
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
148
166
|
className: DEFAULT_CLASS
|
|
149
167
|
}, title && !hide_title && /*#__PURE__*/_react.default.createElement(_copReactComponents.LargeHeading, {
|
|
150
168
|
key: "heading"
|
|
151
|
-
}, title), errors && errors.length > 0 && /*#__PURE__*/_react.default.createElement(_copReactComponents.ErrorSummary, {
|
|
169
|
+
}, cysa ? cysaTitle : title), errors && errors.length > 0 && /*#__PURE__*/_react.default.createElement(_copReactComponents.ErrorSummary, {
|
|
152
170
|
errors: errors
|
|
153
171
|
}), type === 'task-list-cya' && pages.length > 0 && sections && sections.map(function (section) {
|
|
154
172
|
return section.tasks.map(function (task) {
|
|
@@ -147,16 +147,16 @@ describe('components.CollectionPage', function () {
|
|
|
147
147
|
var checkInputField = function checkInputField(formGroup, fieldId, lbl, hnt, val) {
|
|
148
148
|
expect(formGroup.tagName).toEqual('DIV');
|
|
149
149
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
150
|
-
var label = formGroup.childNodes[0];
|
|
150
|
+
var label = formGroup.childNodes[0].childNodes[0].childNodes[0];
|
|
151
151
|
expect(label.tagName).toEqual('LABEL');
|
|
152
152
|
expect(label.classList).toContain('govuk-label');
|
|
153
153
|
expect(label.textContent).toEqual(lbl);
|
|
154
154
|
expect(label.getAttribute('for')).toEqual(fieldId);
|
|
155
|
-
var hint = formGroup.childNodes[1];
|
|
155
|
+
var hint = formGroup.childNodes[0].childNodes[1];
|
|
156
156
|
expect(hint.tagName).toEqual('SPAN');
|
|
157
157
|
expect(hint.classList).toContain('govuk-hint');
|
|
158
158
|
expect(hint.textContent).toEqual(hnt);
|
|
159
|
-
var input = formGroup.childNodes[2];
|
|
159
|
+
var input = formGroup.childNodes[0].childNodes[2];
|
|
160
160
|
expect(input.tagName).toEqual('INPUT');
|
|
161
161
|
expect(input.classList).toContain('govuk-input');
|
|
162
162
|
expect(input.id).toEqual(fieldId);
|
|
@@ -167,16 +167,16 @@ describe('components.CollectionPage', function () {
|
|
|
167
167
|
var checkAutoCompleteField = function checkAutoCompleteField(formGroup, fieldId, lbl, hnt, val) {
|
|
168
168
|
expect(formGroup.tagName).toEqual('DIV');
|
|
169
169
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
170
|
-
var label = formGroup.childNodes[0];
|
|
170
|
+
var label = formGroup.childNodes[0].childNodes[0].childNodes[0];
|
|
171
171
|
expect(label.tagName).toEqual('LABEL');
|
|
172
172
|
expect(label.classList).toContain('govuk-label');
|
|
173
173
|
expect(label.textContent).toEqual(lbl);
|
|
174
174
|
expect(label.getAttribute('for')).toEqual(fieldId);
|
|
175
|
-
var hint = formGroup.childNodes[1];
|
|
175
|
+
var hint = formGroup.childNodes[0].childNodes[1];
|
|
176
176
|
expect(hint.tagName).toEqual('SPAN');
|
|
177
177
|
expect(hint.classList).toContain('govuk-hint');
|
|
178
178
|
expect(hint.textContent).toEqual(hnt);
|
|
179
|
-
var outerWrapper = formGroup.childNodes[2];
|
|
179
|
+
var outerWrapper = formGroup.childNodes[0].childNodes[2];
|
|
180
180
|
expect(outerWrapper.classList).toContain('hods-autocomplete__outer-wrapper');
|
|
181
181
|
var autocomplete = outerWrapper.childNodes[0];
|
|
182
182
|
expect(autocomplete.classList).toContain('hods-autocomplete__wrapper');
|
|
@@ -293,7 +293,7 @@ describe('components.CollectionPage', function () {
|
|
|
293
293
|
page = container.childNodes[0];
|
|
294
294
|
expect(page.tagName).toEqual('DIV'); // Change the input.
|
|
295
295
|
|
|
296
|
-
input = page.childNodes[1].childNodes[2];
|
|
296
|
+
input = page.childNodes[1].childNodes[0].childNodes[2];
|
|
297
297
|
NEW_VALUE = "".concat(VALUE, ".");
|
|
298
298
|
EVENT = {
|
|
299
299
|
target: {
|
|
@@ -327,7 +327,7 @@ describe('components.CollectionPage', function () {
|
|
|
327
327
|
})), container = _renderWithValidation4.container;
|
|
328
328
|
page = container.childNodes[0]; // Change the input.
|
|
329
329
|
|
|
330
|
-
input = page.childNodes[1].childNodes[2];
|
|
330
|
+
input = page.childNodes[1].childNodes[0].childNodes[2];
|
|
331
331
|
NEW_VALUE = "".concat(VALUE, ".");
|
|
332
332
|
CHANGE_EVENT = {
|
|
333
333
|
target: {
|
|
@@ -374,7 +374,7 @@ describe('components.CollectionPage', function () {
|
|
|
374
374
|
})), container = _renderWithValidation5.container;
|
|
375
375
|
page = container.childNodes[0]; // Change the input.
|
|
376
376
|
|
|
377
|
-
input = page.childNodes[1].childNodes[2];
|
|
377
|
+
input = page.childNodes[1].childNodes[0].childNodes[2];
|
|
378
378
|
NEW_VALUE = "".concat(VALUE, ".");
|
|
379
379
|
CHANGE_EVENT = {
|
|
380
380
|
target: {
|
|
@@ -88,16 +88,16 @@ describe('components.FormComponent.Collection', function () {
|
|
|
88
88
|
formGroup = itemContainer.childNodes[0];
|
|
89
89
|
expect(formGroup.tagName).toEqual('DIV');
|
|
90
90
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
91
|
-
label = formGroup.childNodes[0];
|
|
91
|
+
label = formGroup.childNodes[0].childNodes[0].childNodes[0];
|
|
92
92
|
expect(label.tagName).toEqual('LABEL');
|
|
93
93
|
expect(label.classList).toContain('govuk-label');
|
|
94
94
|
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
95
95
|
expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
96
|
-
hint = formGroup.childNodes[1];
|
|
96
|
+
hint = formGroup.childNodes[0].childNodes[1];
|
|
97
97
|
expect(hint.tagName).toEqual('SPAN');
|
|
98
98
|
expect(hint.classList).toContain('govuk-hint');
|
|
99
99
|
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
100
|
-
input = formGroup.childNodes[2];
|
|
100
|
+
input = formGroup.childNodes[0].childNodes[2];
|
|
101
101
|
expect(input.tagName).toEqual('INPUT');
|
|
102
102
|
expect(input.classList).toContain('govuk-input');
|
|
103
103
|
expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
@@ -144,7 +144,7 @@ describe('components.FormComponent.Collection', function () {
|
|
|
144
144
|
c = container.childNodes[0];
|
|
145
145
|
item = c.childNodes[0];
|
|
146
146
|
formGroup = item.childNodes[1].childNodes[0];
|
|
147
|
-
input = formGroup.childNodes[2];
|
|
147
|
+
input = formGroup.childNodes[0].childNodes[2];
|
|
148
148
|
NEW_TEXT_VALUE = 'bravo';
|
|
149
149
|
EVENT = {
|
|
150
150
|
target: {
|
|
@@ -354,16 +354,16 @@ describe('components.FormComponent.Collection', function () {
|
|
|
354
354
|
formGroup = itemContainer.childNodes[0];
|
|
355
355
|
expect(formGroup.tagName).toEqual('DIV');
|
|
356
356
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
357
|
-
label = formGroup.childNodes[0];
|
|
357
|
+
label = formGroup.childNodes[0].childNodes[0].childNodes[0];
|
|
358
358
|
expect(label.tagName).toEqual('LABEL');
|
|
359
359
|
expect(label.classList).toContain('govuk-label');
|
|
360
360
|
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
361
361
|
expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
362
|
-
hint = formGroup.childNodes[1];
|
|
362
|
+
hint = formGroup.childNodes[0].childNodes[1];
|
|
363
363
|
expect(hint.tagName).toEqual('SPAN');
|
|
364
364
|
expect(hint.classList).toContain('govuk-hint');
|
|
365
365
|
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
366
|
-
input = formGroup.childNodes[2];
|
|
366
|
+
input = formGroup.childNodes[0].childNodes[2];
|
|
367
367
|
expect(input.tagName).toEqual('DIV'); // Now readonly, so a DIV.
|
|
368
368
|
|
|
369
369
|
expect(input.classList).toContain('hods-readonly'); // Now readonly, so hods-readonly
|
|
@@ -76,16 +76,16 @@ describe('components.FormComponent.Container', function () {
|
|
|
76
76
|
formGroup = c.childNodes[0];
|
|
77
77
|
expect(formGroup.tagName).toEqual('DIV');
|
|
78
78
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
79
|
-
label = formGroup.childNodes[0];
|
|
79
|
+
label = formGroup.childNodes[0].childNodes[0].childNodes[0];
|
|
80
80
|
expect(label.tagName).toEqual('LABEL');
|
|
81
81
|
expect(label.classList).toContain('govuk-label');
|
|
82
82
|
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
83
83
|
expect(label.getAttribute('for')).toEqual("".concat(ID, ".").concat(TEXT_ID));
|
|
84
|
-
hint = formGroup.childNodes[1];
|
|
84
|
+
hint = formGroup.childNodes[0].childNodes[1];
|
|
85
85
|
expect(hint.tagName).toEqual('SPAN');
|
|
86
86
|
expect(hint.classList).toContain('govuk-hint');
|
|
87
87
|
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
88
|
-
input = formGroup.childNodes[2];
|
|
88
|
+
input = formGroup.childNodes[0].childNodes[2];
|
|
89
89
|
expect(input.tagName).toEqual('INPUT');
|
|
90
90
|
expect(input.classList).toContain('govuk-input');
|
|
91
91
|
expect(input.id).toEqual("".concat(ID, ".").concat(TEXT_ID));
|
|
@@ -133,16 +133,16 @@ describe('components.FormComponent.Container', function () {
|
|
|
133
133
|
formGroup = nested.childNodes[0];
|
|
134
134
|
expect(formGroup.tagName).toEqual('DIV');
|
|
135
135
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
136
|
-
label = formGroup.childNodes[0];
|
|
136
|
+
label = formGroup.childNodes[0].childNodes[0].childNodes[0];
|
|
137
137
|
expect(label.tagName).toEqual('LABEL');
|
|
138
138
|
expect(label.classList).toContain('govuk-label');
|
|
139
139
|
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
140
140
|
expect(label.getAttribute('for')).toEqual("".concat(ID, ".").concat(NESTED_ID, ".").concat(TEXT_ID));
|
|
141
|
-
hint = formGroup.childNodes[1];
|
|
141
|
+
hint = formGroup.childNodes[0].childNodes[1];
|
|
142
142
|
expect(hint.tagName).toEqual('SPAN');
|
|
143
143
|
expect(hint.classList).toContain('govuk-hint');
|
|
144
144
|
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
145
|
-
input = formGroup.childNodes[2];
|
|
145
|
+
input = formGroup.childNodes[0].childNodes[2];
|
|
146
146
|
expect(input.tagName).toEqual('INPUT');
|
|
147
147
|
expect(input.classList).toContain('govuk-input');
|
|
148
148
|
expect(input.id).toEqual("".concat(ID, ".").concat(NESTED_ID, ".").concat(TEXT_ID));
|
|
@@ -188,7 +188,7 @@ describe('components.FormComponent.Container', function () {
|
|
|
188
188
|
|
|
189
189
|
c = container.childNodes[0];
|
|
190
190
|
formGroup = c.childNodes[0];
|
|
191
|
-
input = formGroup.childNodes[2];
|
|
191
|
+
input = formGroup.childNodes[0].childNodes[2];
|
|
192
192
|
NEW_TEXT_VALUE = 'bravo';
|
|
193
193
|
EVENT = {
|
|
194
194
|
target: {
|
|
@@ -253,7 +253,7 @@ describe('components.FormComponent.Container', function () {
|
|
|
253
253
|
|
|
254
254
|
c = container.childNodes[0];
|
|
255
255
|
formGroup = c.childNodes[0];
|
|
256
|
-
input = formGroup.childNodes[2].childNodes[0];
|
|
256
|
+
input = formGroup.childNodes[0].childNodes[2].childNodes[0];
|
|
257
257
|
FILE_EXTENSION = 'json';
|
|
258
258
|
FILE_NAME = "test.".concat(FILE_EXTENSION);
|
|
259
259
|
FILE_TYPE = 'application/JSON';
|
|
@@ -314,16 +314,16 @@ describe('components.FormComponent.Container', function () {
|
|
|
314
314
|
formGroup = c.childNodes[0];
|
|
315
315
|
expect(formGroup.tagName).toEqual('DIV');
|
|
316
316
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
317
|
-
label = formGroup.childNodes[0];
|
|
317
|
+
label = formGroup.childNodes[0].childNodes[0].childNodes[0];
|
|
318
318
|
expect(label.tagName).toEqual('LABEL');
|
|
319
319
|
expect(label.classList).toContain('govuk-label');
|
|
320
320
|
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
321
321
|
expect(label.getAttribute('for')).toEqual("".concat(ID, ".").concat(TEXT_ID));
|
|
322
|
-
hint = formGroup.childNodes[1];
|
|
322
|
+
hint = formGroup.childNodes[0].childNodes[1];
|
|
323
323
|
expect(hint.tagName).toEqual('SPAN');
|
|
324
324
|
expect(hint.classList).toContain('govuk-hint');
|
|
325
325
|
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
326
|
-
input = formGroup.childNodes[2];
|
|
326
|
+
input = formGroup.childNodes[0].childNodes[2];
|
|
327
327
|
expect(input.tagName).toEqual('INPUT');
|
|
328
328
|
expect(input.classList).toContain('govuk-input');
|
|
329
329
|
expect(input.id).toEqual("".concat(ID, ".").concat(TEXT_ID));
|
|
@@ -396,16 +396,16 @@ describe('components.FormComponent.Container', function () {
|
|
|
396
396
|
formGroup = c.childNodes[0];
|
|
397
397
|
expect(formGroup.tagName).toEqual('DIV');
|
|
398
398
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
399
|
-
label = formGroup.childNodes[0];
|
|
399
|
+
label = formGroup.childNodes[0].childNodes[0].childNodes[0];
|
|
400
400
|
expect(label.tagName).toEqual('LABEL');
|
|
401
401
|
expect(label.classList).toContain('govuk-label');
|
|
402
402
|
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
403
403
|
expect(label.getAttribute('for')).toEqual("".concat(ID, ".").concat(TEXT_ID));
|
|
404
|
-
hint = formGroup.childNodes[1];
|
|
404
|
+
hint = formGroup.childNodes[0].childNodes[1];
|
|
405
405
|
expect(hint.tagName).toEqual('SPAN');
|
|
406
406
|
expect(hint.classList).toContain('govuk-hint');
|
|
407
407
|
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
408
|
-
input = formGroup.childNodes[2];
|
|
408
|
+
input = formGroup.childNodes[0].childNodes[2];
|
|
409
409
|
expect(input.tagName).toEqual('DIV'); // Now readonly, so a DIV.
|
|
410
410
|
|
|
411
411
|
expect(input.classList).toContain('hods-readonly'); // Now readonly, so hods-readonly
|
|
@@ -43,16 +43,16 @@ describe('components', function () {
|
|
|
43
43
|
formGroup = container.childNodes[0];
|
|
44
44
|
expect(formGroup.tagName).toEqual('DIV');
|
|
45
45
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
46
|
-
label = formGroup.childNodes[0];
|
|
46
|
+
label = formGroup.childNodes[0].childNodes[0].childNodes[0];
|
|
47
47
|
expect(label.tagName).toEqual('LABEL');
|
|
48
48
|
expect(label.classList).toContain('govuk-label');
|
|
49
49
|
expect(label.textContent).toEqual("".concat(COMPONENT.label, " (optional)"));
|
|
50
50
|
expect(label.getAttribute('for')).toEqual(ID);
|
|
51
|
-
hint = formGroup.childNodes[1];
|
|
51
|
+
hint = formGroup.childNodes[0].childNodes[1];
|
|
52
52
|
expect(hint.tagName).toEqual('SPAN');
|
|
53
53
|
expect(hint.classList).toContain('govuk-hint');
|
|
54
54
|
expect(hint.textContent).toEqual(COMPONENT.hint);
|
|
55
|
-
input = formGroup.childNodes[2];
|
|
55
|
+
input = formGroup.childNodes[0].childNodes[2];
|
|
56
56
|
expect(input.tagName).toEqual('INPUT');
|
|
57
57
|
expect(input.classList).toContain('govuk-input');
|
|
58
58
|
expect(input.id).toEqual(ID);
|
|
@@ -238,16 +238,16 @@ describe('components', function () {
|
|
|
238
238
|
formGroup = container.childNodes[0];
|
|
239
239
|
expect(formGroup.tagName).toEqual('DIV');
|
|
240
240
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
241
|
-
label = formGroup.childNodes[0];
|
|
241
|
+
label = formGroup.childNodes[0].childNodes[0].childNodes[0];
|
|
242
242
|
expect(label.tagName).toEqual('LABEL');
|
|
243
243
|
expect(label.classList).toContain('govuk-label');
|
|
244
244
|
expect(label.textContent).toEqual('Interpolated Text component (optional)');
|
|
245
245
|
expect(label.getAttribute('for')).toEqual(ID);
|
|
246
|
-
hint = formGroup.childNodes[1];
|
|
246
|
+
hint = formGroup.childNodes[0].childNodes[1];
|
|
247
247
|
expect(hint.tagName).toEqual('SPAN');
|
|
248
248
|
expect(hint.classList).toContain('govuk-hint');
|
|
249
249
|
expect(hint.textContent).toEqual(COMPONENT.hint);
|
|
250
|
-
input = formGroup.childNodes[2];
|
|
250
|
+
input = formGroup.childNodes[0].childNodes[2];
|
|
251
251
|
expect(input.tagName).toEqual('INPUT');
|
|
252
252
|
expect(input.classList).toContain('govuk-input');
|
|
253
253
|
expect(input.id).toEqual(ID);
|
|
@@ -73,13 +73,14 @@ var FormPage = function FormPage(_ref) {
|
|
|
73
73
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
74
74
|
patchLabel = _useState4[0],
|
|
75
75
|
setPatchLabel = _useState4[1];
|
|
76
|
+
|
|
77
|
+
var docTitle = (0, _react.useState)(document.title);
|
|
76
78
|
/**
|
|
77
79
|
* Handle the state of the data directly within the page.
|
|
78
80
|
* This is so that the overall form data isn't affected until such
|
|
79
81
|
* time as the onAction handler is invoked.
|
|
80
82
|
*/
|
|
81
83
|
|
|
82
|
-
|
|
83
84
|
var onPageChange = function onPageChange(_ref2) {
|
|
84
85
|
var target = _ref2.target;
|
|
85
86
|
page.formData[target.name] = target.value;
|
|
@@ -91,6 +92,10 @@ var FormPage = function FormPage(_ref) {
|
|
|
91
92
|
});
|
|
92
93
|
};
|
|
93
94
|
|
|
95
|
+
(0, _react.useEffect)(function () {
|
|
96
|
+
document.title = errors.length > 0 ? 'Error: ' + docTitle : docTitle;
|
|
97
|
+
}, [errors, docTitle]);
|
|
98
|
+
|
|
94
99
|
var classes = _utils.default.classBuilder(classBlock, classModifiers, className);
|
|
95
100
|
|
|
96
101
|
page.actions = (_page$actions = page.actions) === null || _page$actions === void 0 ? void 0 : _page$actions.map(function (action) {
|
|
@@ -135,16 +135,16 @@ describe('components.FormPage', function () {
|
|
|
135
135
|
var checkInputField = function checkInputField(formGroup, fieldId, lbl, hnt, val) {
|
|
136
136
|
expect(formGroup.tagName).toEqual('DIV');
|
|
137
137
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
138
|
-
var label = formGroup.childNodes[0];
|
|
138
|
+
var label = formGroup.childNodes[0].childNodes[0].childNodes[0];
|
|
139
139
|
expect(label.tagName).toEqual('LABEL');
|
|
140
140
|
expect(label.classList).toContain('govuk-label');
|
|
141
141
|
expect(label.textContent).toEqual(lbl);
|
|
142
142
|
expect(label.getAttribute('for')).toEqual(fieldId);
|
|
143
|
-
var hint = formGroup.childNodes[1];
|
|
143
|
+
var hint = formGroup.childNodes[0].childNodes[1];
|
|
144
144
|
expect(hint.tagName).toEqual('SPAN');
|
|
145
145
|
expect(hint.classList).toContain('govuk-hint');
|
|
146
146
|
expect(hint.textContent).toEqual(hnt);
|
|
147
|
-
var input = formGroup.childNodes[2];
|
|
147
|
+
var input = formGroup.childNodes[0].childNodes[2];
|
|
148
148
|
expect(input.tagName).toEqual('INPUT');
|
|
149
149
|
expect(input.classList).toContain('govuk-input');
|
|
150
150
|
expect(input.id).toEqual(fieldId);
|
|
@@ -155,16 +155,16 @@ describe('components.FormPage', function () {
|
|
|
155
155
|
var checkAutoCompleteField = function checkAutoCompleteField(formGroup, fieldId, lbl, hnt, val) {
|
|
156
156
|
expect(formGroup.tagName).toEqual('DIV');
|
|
157
157
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
158
|
-
var label = formGroup.childNodes[0];
|
|
158
|
+
var label = formGroup.childNodes[0].childNodes[0].childNodes[0];
|
|
159
159
|
expect(label.tagName).toEqual('LABEL');
|
|
160
160
|
expect(label.classList).toContain('govuk-label');
|
|
161
161
|
expect(label.textContent).toEqual(lbl);
|
|
162
162
|
expect(label.getAttribute('for')).toEqual(fieldId);
|
|
163
|
-
var hint = formGroup.childNodes[1];
|
|
163
|
+
var hint = formGroup.childNodes[0].childNodes[1];
|
|
164
164
|
expect(hint.tagName).toEqual('SPAN');
|
|
165
165
|
expect(hint.classList).toContain('govuk-hint');
|
|
166
166
|
expect(hint.textContent).toEqual(hnt);
|
|
167
|
-
var outerWrapper = formGroup.childNodes[2];
|
|
167
|
+
var outerWrapper = formGroup.childNodes[0].childNodes[2];
|
|
168
168
|
expect(outerWrapper.classList).toContain('hods-autocomplete__outer-wrapper');
|
|
169
169
|
var autocomplete = outerWrapper.childNodes[0];
|
|
170
170
|
expect(autocomplete.classList).toContain('hods-autocomplete__wrapper');
|
|
@@ -278,7 +278,7 @@ describe('components.FormPage', function () {
|
|
|
278
278
|
page = container.childNodes[0];
|
|
279
279
|
expect(page.tagName).toEqual('DIV'); // Change the input.
|
|
280
280
|
|
|
281
|
-
input = page.childNodes[1].childNodes[2];
|
|
281
|
+
input = page.childNodes[1].childNodes[0].childNodes[2];
|
|
282
282
|
NEW_VALUE = "".concat(VALUE, ".");
|
|
283
283
|
EVENT = {
|
|
284
284
|
target: {
|
|
@@ -312,7 +312,7 @@ describe('components.FormPage', function () {
|
|
|
312
312
|
})), container = _renderWithValidation4.container;
|
|
313
313
|
page = container.childNodes[0]; // Change the input.
|
|
314
314
|
|
|
315
|
-
input = page.childNodes[1].childNodes[2];
|
|
315
|
+
input = page.childNodes[1].childNodes[0].childNodes[2];
|
|
316
316
|
NEW_VALUE = "".concat(VALUE, ".");
|
|
317
317
|
CHANGE_EVENT = {
|
|
318
318
|
target: {
|
|
@@ -170,7 +170,17 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
170
170
|
var _useState19 = (0, _react.useState)(false),
|
|
171
171
|
_useState20 = _slicedToArray(_useState19, 2),
|
|
172
172
|
goingBack = _useState20[0],
|
|
173
|
-
setGoingBack = _useState20[1];
|
|
173
|
+
setGoingBack = _useState20[1];
|
|
174
|
+
|
|
175
|
+
var _useState21 = (0, _react.useState)(false),
|
|
176
|
+
_useState22 = _slicedToArray(_useState21, 2),
|
|
177
|
+
continueOnly = _useState22[0],
|
|
178
|
+
setContinueOnly = _useState22[1];
|
|
179
|
+
|
|
180
|
+
var _useState23 = (0, _react.useState)(),
|
|
181
|
+
_useState24 = _slicedToArray(_useState23, 2),
|
|
182
|
+
currentTaskListPage = _useState24[0],
|
|
183
|
+
setCurrentTaskListPage = _useState24[1]; // Set up hooks.
|
|
174
184
|
|
|
175
185
|
|
|
176
186
|
var _useHooks = (0, _hooks.useHooks)(),
|
|
@@ -183,13 +193,29 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
183
193
|
validate = _useValidation.validate; // Need to set submission data when going back
|
|
184
194
|
|
|
185
195
|
|
|
186
|
-
window.onpopstate = function () {
|
|
196
|
+
window.onpopstate = function (e) {
|
|
187
197
|
var _formState$page;
|
|
188
198
|
|
|
189
199
|
if (document.location.hash) {
|
|
190
200
|
return;
|
|
191
201
|
}
|
|
192
202
|
|
|
203
|
+
if (e.state && e.state.continueOnly !== undefined) {
|
|
204
|
+
var _e$state;
|
|
205
|
+
|
|
206
|
+
setContinueOnly((_e$state = e.state) === null || _e$state === void 0 ? void 0 : _e$state.continueOnly);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (e.state && e.state.fullPages !== undefined) {
|
|
210
|
+
setCurrentTask(function (prev) {
|
|
211
|
+
var _e$state2;
|
|
212
|
+
|
|
213
|
+
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
214
|
+
fullPages: (_e$state2 = e.state) === null || _e$state2 === void 0 ? void 0 : _e$state2.fullPages
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
193
219
|
setGoingBack(true);
|
|
194
220
|
hooks.onGoingBack();
|
|
195
221
|
clearErrors();
|
|
@@ -292,9 +318,10 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
292
318
|
}, [currentTask.fullPages, data, hubDetails === null || hubDetails === void 0 ? void 0 : hubDetails.sections, hubDetails === null || hubDetails === void 0 ? void 0 : hubDetails.nonSequential]);
|
|
293
319
|
|
|
294
320
|
var onPageChange = function onPageChange(newPageId) {
|
|
321
|
+
var state = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
295
322
|
clearErrors();
|
|
296
323
|
setPageId(newPageId);
|
|
297
|
-
hooks.onPageChange(newPageId);
|
|
324
|
+
hooks.onPageChange(newPageId, state);
|
|
298
325
|
};
|
|
299
326
|
|
|
300
327
|
(0, _react.useEffect)(function () {
|
|
@@ -336,8 +363,13 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
336
363
|
break;
|
|
337
364
|
|
|
338
365
|
case _models.PageAction.TYPES.SAVE_AND_NAVIGATE:
|
|
366
|
+
var state = {
|
|
367
|
+
'continueOnly': false,
|
|
368
|
+
'fullPages': currentTask.fullPages
|
|
369
|
+
};
|
|
370
|
+
|
|
339
371
|
pageUpdate = function pageUpdate() {
|
|
340
|
-
return _handlers.default.navigate(action, pageId, onPageChange);
|
|
372
|
+
return _handlers.default.navigate(action, pageId, onPageChange, state);
|
|
341
373
|
};
|
|
342
374
|
|
|
343
375
|
break;
|
|
@@ -450,6 +482,8 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
450
482
|
}
|
|
451
483
|
|
|
452
484
|
if (page) {
|
|
485
|
+
setContinueOnly(false);
|
|
486
|
+
|
|
453
487
|
_handlers.default.cyaAction(page, pageId, onPageChange);
|
|
454
488
|
}
|
|
455
489
|
}; //Kick off a task, gather required pages and move to the correct point
|
|
@@ -472,7 +506,18 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
472
506
|
}
|
|
473
507
|
} else if (currentTask.state === _models.TaskStates.TYPES.IN_PROGRESS) {
|
|
474
508
|
var _currentPage = data.formStatus.tasks[currentTask.name].currentPage;
|
|
475
|
-
|
|
509
|
+
|
|
510
|
+
if (currentTask.pages.length > 1 && _currentPage !== _models.FormPages.CYA && _currentPage !== currentTask.pages[0]) {
|
|
511
|
+
setContinueOnly(true);
|
|
512
|
+
setCurrentTaskListPage(_currentPage);
|
|
513
|
+
var state = {
|
|
514
|
+
'continueOnly': true,
|
|
515
|
+
'fullPages': currentTask.fullPages
|
|
516
|
+
};
|
|
517
|
+
onPageChange(_models.FormPages.CYA, state);
|
|
518
|
+
} else {
|
|
519
|
+
onPageChange(_currentPage);
|
|
520
|
+
}
|
|
476
521
|
} else if (currentTask.firstPage) {
|
|
477
522
|
var _currentPage2 = currentTask.firstPage;
|
|
478
523
|
onPageChange(_currentPage2 || currentTask.pages[0]);
|
|
@@ -575,6 +620,12 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
575
620
|
onPageChange(_helpers.default.getNextPageId(type, pages, pageId, action, (_formState$page4 = formState.page) === null || _formState$page4 === void 0 ? void 0 : _formState$page4.formData));
|
|
576
621
|
}
|
|
577
622
|
|
|
623
|
+
if (action.type === _models.PageAction.TYPES.CONTINUE) {
|
|
624
|
+
var currentPage = data.formStatus.tasks[currentTask.name].currentPage;
|
|
625
|
+
onPageChange(currentPage || currentTask.pages[0]);
|
|
626
|
+
setContinueOnly(false);
|
|
627
|
+
}
|
|
628
|
+
|
|
578
629
|
if (action.type === _models.PageAction.TYPES.CANCEL) {
|
|
579
630
|
hooks.onCancel();
|
|
580
631
|
}
|
|
@@ -583,7 +634,11 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
583
634
|
var classes = _utils.default.classBuilder(classBlock, classModifiers, className);
|
|
584
635
|
|
|
585
636
|
if (hub === _models.HubFormats.TASK) {
|
|
586
|
-
|
|
637
|
+
if (continueOnly) {
|
|
638
|
+
cya.actions = [_models.PageAction.TYPES.CONTINUE];
|
|
639
|
+
} else {
|
|
640
|
+
cya.actions = [_models.PageAction.TYPES.SAVE_AND_CONTINUE, _models.PageAction.TYPES.SAVE_AND_RETURN];
|
|
641
|
+
}
|
|
587
642
|
}
|
|
588
643
|
|
|
589
644
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
@@ -599,7 +654,9 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
599
654
|
hide_title: hide_title,
|
|
600
655
|
noChangeAction: noChangeAction,
|
|
601
656
|
sections: typeof hubDetails !== 'undefined' ? hubDetails.sections : [],
|
|
602
|
-
type: type
|
|
657
|
+
type: type,
|
|
658
|
+
cysa: continueOnly,
|
|
659
|
+
currentPage: currentTaskListPage
|
|
603
660
|
})), hub === _models.HubFormats.TASK && formState.pageId === _models.FormPages.HUB && /*#__PURE__*/_react.default.createElement(_TaskList.default, _extends({}, hubDetails, {
|
|
604
661
|
refNumber: data.businessKey,
|
|
605
662
|
onTaskAction: onTaskAction
|