@ukhomeoffice/cop-react-form-renderer 6.16.0-charlie → 6.16.0

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.
Files changed (19) hide show
  1. package/dist/components/CheckYourAnswers/CheckYourAnswers.js +5 -1
  2. package/dist/components/FormRenderer/FormRenderer.js +0 -16
  3. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-hidden-component-with-nested-questions-visible-elsewhere.json +118 -0
  4. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-nested-answers-hidden-by-option-visible-elsewhere.json +113 -0
  5. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-page-nested-component.json +26003 -0
  6. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/input/data-hidden-component-with-nested-questions-visible-elsewhere.json +12 -0
  7. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/input/data-nested-answers-hidden-by-option-visible-elsewhere.json +12 -0
  8. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/input/data-page-nested-component.json +63 -0
  9. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/output/data-hidden-component-with-nested-questions-visible-elsewhere-removed.json +11 -0
  10. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/output/data-nested-answers-hidden-by-option-visible-elsewhere-removed.json +12 -0
  11. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/output/data-page-nested-component.json +63 -0
  12. package/dist/components/FormRenderer/helpers/clearOutUncompletedRoutes.js +17 -14
  13. package/dist/components/FormRenderer/helpers/clearOutUncompletedRoutes.test.js +31 -0
  14. package/dist/components/FormRenderer/helpers/clearOutUncompletedRoutesUtils.js +44 -35
  15. package/dist/components/FormRenderer/onPageAction.js +36 -0
  16. package/dist/components/FormRenderer/onPageAction.test.js +113 -0
  17. package/dist/utils/Validate/validateComponent.js +4 -1
  18. package/dist/utils/canOverrideFieldRequired.js +18 -0
  19. package/package.json +2 -2
@@ -127,12 +127,16 @@ const CheckYourAnswers = _ref => {
127
127
  }
128
128
  })));
129
129
  };
130
+ const getDedupedErrors = () => {
131
+ const dedupedErrors = Array.from(new Set(errors.map(a => a.id))).map(id => errors.find(b => b.id === id));
132
+ return dedupedErrors;
133
+ };
130
134
  return /*#__PURE__*/_react.default.createElement("div", {
131
135
  className: DEFAULT_CLASS
132
136
  }, title && !hide_title && /*#__PURE__*/_react.default.createElement(_copReactComponents.LargeHeading, {
133
137
  key: "heading"
134
138
  }, title), errors && errors.length > 0 && /*#__PURE__*/_react.default.createElement(_copReactComponents.ErrorSummary, {
135
- errors: errors
139
+ errors: getDedupedErrors()
136
140
  }), type === _models.FormTypes.TASK_CYA && pages.length > 0 && sections && sections.map(section => section.tasks.filter(task => task.state !== _models.TaskStates.TYPES.SKIPPED).map((task, taskIndex) => {
137
141
  const filterPages = pages.filter(page => task.pages.some(p => p === page.name));
138
142
  return /*#__PURE__*/_react.default.createElement(_react.Fragment, {
@@ -129,17 +129,6 @@ const InternalFormRenderer = _ref2 => {
129
129
  validate
130
130
  } = (0, _hooks.useValidation)();
131
131
 
132
- // Set focus to header for accessibility, Screen reader to anounce the page heading
133
- const setFocusToHeading = () => {
134
- if (document) {
135
- const header = Array.from(document.getElementsByTagName('h1')).pop();
136
- if (header && document.activeElement !== header) {
137
- header.setAttribute('tabIndex', '-1');
138
- header.focus();
139
- }
140
- }
141
- };
142
-
143
132
  // Need to set submission data when going back
144
133
  window.onpopstate = e => {
145
134
  var _formState$page;
@@ -203,11 +192,6 @@ const InternalFormRenderer = _ref2 => {
203
192
  setHub(_utils.default.Hub.get(type, _hub, components, _objectSpread({}, data)));
204
193
  }, [type, _hub, data, components, setHub]);
205
194
 
206
- // Set focus to heading for accessibility
207
- (0, _react.useEffect)(() => {
208
- setFocusToHeading();
209
- }, [formState]);
210
-
211
195
  // Form state.
212
196
  (0, _react.useEffect)(() => {
213
197
  var _formState$page2;
@@ -0,0 +1,118 @@
1
+ {
2
+ "id": "example-form",
3
+ "cleanseHiddenData": true,
4
+ "version": "0.0.1",
5
+ "name": "example-form",
6
+ "title": "Example form",
7
+ "type": "form",
8
+ "components": [
9
+ {
10
+ "id": "alpha",
11
+ "fieldId": "alpha",
12
+ "label": "Alpha",
13
+ "type": "text"
14
+ },
15
+ {
16
+ "id": "bravo",
17
+ "fieldId": "bravo",
18
+ "label": "Bravo",
19
+ "type": "text"
20
+ },
21
+ {
22
+ "id": "person",
23
+ "fieldId": "person",
24
+ "type": "container",
25
+ "components": [
26
+ {
27
+ "id": "telephone_visible",
28
+ "fieldId": "telephone",
29
+ "label": "telephone_visible",
30
+ "type": "text"
31
+ },
32
+ {
33
+ "id": "telephoneKnown",
34
+ "fieldId": "telephoneKnown",
35
+ "type": "radios",
36
+ "data": {
37
+ "options": [
38
+ {
39
+ "value": "yes",
40
+ "label": "Yes",
41
+ "nested": [
42
+ {
43
+ "id": "telephone",
44
+ "fieldId": "telephone",
45
+ "type": "text",
46
+ "label": "Telephone",
47
+ "required": true
48
+ }
49
+ ]
50
+ },
51
+ {
52
+ "value": "no",
53
+ "label": "No"
54
+ }
55
+ ]
56
+ },
57
+ "show_when": {
58
+ "op": "=",
59
+ "field": "bravo",
60
+ "value": "NOT-bravo-value"
61
+ }
62
+ },
63
+ {
64
+ "id": "name",
65
+ "fieldId": "name",
66
+ "label": "Name",
67
+ "type": "text"
68
+ }
69
+ ]
70
+ },
71
+ {
72
+ "id": "gamma",
73
+ "fieldId": "gamma",
74
+ "label": "Gamma",
75
+ "type": "text"
76
+ },
77
+ {
78
+ "id": "epsilon",
79
+ "fieldId": "epsilon",
80
+ "label": "Epsilon",
81
+ "type": "text"
82
+ }
83
+ ],
84
+ "pages": [
85
+ {
86
+ "id": "general",
87
+ "name": "general",
88
+ "title": "General information",
89
+ "components": [
90
+ {
91
+ "use": "alpha"
92
+ },
93
+ {
94
+ "use": "bravo"
95
+ },
96
+ {
97
+ "use": "person"
98
+ },
99
+ {
100
+ "use": "gamma"
101
+ },
102
+ {
103
+ "use": "epsilon"
104
+ }
105
+ ],
106
+ "actions": [
107
+ "submit",
108
+ {
109
+ "type": "cancel",
110
+ "page": "",
111
+ "validate": false,
112
+ "classModifiers": "secondary",
113
+ "label": "Cancel"
114
+ }
115
+ ]
116
+ }
117
+ ]
118
+ }
@@ -0,0 +1,113 @@
1
+ {
2
+ "id": "example-form",
3
+ "cleanseHiddenData": true,
4
+ "version": "0.0.1",
5
+ "name": "example-form",
6
+ "title": "Example form",
7
+ "type": "form",
8
+ "components": [
9
+ {
10
+ "id": "alpha",
11
+ "fieldId": "alpha",
12
+ "label": "Alpha",
13
+ "type": "text"
14
+ },
15
+ {
16
+ "id": "bravo",
17
+ "fieldId": "bravo",
18
+ "label": "Bravo",
19
+ "type": "text"
20
+ },
21
+ {
22
+ "id": "person",
23
+ "fieldId": "person",
24
+ "type": "container",
25
+ "components": [
26
+ {
27
+ "id": "telephone_visible",
28
+ "fieldId": "telephone",
29
+ "label": "telephone_visible",
30
+ "type": "text"
31
+ },
32
+ {
33
+ "id": "telephoneKnown",
34
+ "fieldId": "telephoneKnown",
35
+ "type": "radios",
36
+ "data": {
37
+ "options": [
38
+ {
39
+ "value": "yes",
40
+ "label": "Yes",
41
+ "nested": [
42
+ {
43
+ "id": "telephone",
44
+ "fieldId": "telephone",
45
+ "type": "text",
46
+ "label": "Telephone",
47
+ "required": true
48
+ }
49
+ ]
50
+ },
51
+ {
52
+ "value": "no",
53
+ "label": "No"
54
+ }
55
+ ]
56
+ }
57
+ },
58
+ {
59
+ "id": "name",
60
+ "fieldId": "name",
61
+ "label": "Name",
62
+ "type": "text"
63
+ }
64
+ ]
65
+ },
66
+ {
67
+ "id": "gamma",
68
+ "fieldId": "gamma",
69
+ "label": "Gamma",
70
+ "type": "text"
71
+ },
72
+ {
73
+ "id": "epsilon",
74
+ "fieldId": "epsilon",
75
+ "label": "Epsilon",
76
+ "type": "text"
77
+ }
78
+ ],
79
+ "pages": [
80
+ {
81
+ "id": "general",
82
+ "name": "general",
83
+ "title": "General information",
84
+ "components": [
85
+ {
86
+ "use": "alpha"
87
+ },
88
+ {
89
+ "use": "bravo"
90
+ },
91
+ {
92
+ "use": "person"
93
+ },
94
+ {
95
+ "use": "gamma"
96
+ },
97
+ {
98
+ "use": "epsilon"
99
+ }
100
+ ],
101
+ "actions": [
102
+ "submit",
103
+ {
104
+ "type": "cancel",
105
+ "page": "",
106
+ "validate": false,
107
+ "classModifiers": "secondary",
108
+ "label": "Cancel"
109
+ }
110
+ ]
111
+ }
112
+ ]
113
+ }