@ukhomeoffice/cop-react-form-renderer 4.22.2 → 4.22.4-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.
|
@@ -237,10 +237,15 @@ var getComponentByType = function getComponentByType(config) {
|
|
|
237
237
|
|
|
238
238
|
|
|
239
239
|
var getChildJsx = function getChildJsx(parent, child) {
|
|
240
|
-
if (parent.
|
|
241
|
-
var
|
|
240
|
+
if (parent.full_path) {
|
|
241
|
+
var pathParts = parent.full_path.split('.');
|
|
242
|
+
pathParts.pop();
|
|
243
|
+
pathParts.push(child.fieldId);
|
|
244
|
+
child.full_path = pathParts.join('.');
|
|
245
|
+
}
|
|
242
246
|
|
|
243
|
-
|
|
247
|
+
if (parent.formData) {
|
|
248
|
+
child.value = parent.formData[child.fieldId] || _Data.default.getSource(parent.formData, child.full_path) || '';
|
|
244
249
|
}
|
|
245
250
|
|
|
246
251
|
if ('readonly' in child) delete child.readonly;
|
|
@@ -112,4 +112,90 @@ describe('utils.Component.get', function () {
|
|
|
112
112
|
}
|
|
113
113
|
}, _callee2);
|
|
114
114
|
})));
|
|
115
|
+
it('should correctly set the value of the nested component within a container', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
|
|
116
|
+
var CONTAINER_ID, ID, FIELD_ID, LABEL, VALUE, PARENT_CONFIG, NESTED_CONFIG, _renderWithValidation2, container, child, label, input;
|
|
117
|
+
|
|
118
|
+
return regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
119
|
+
while (1) {
|
|
120
|
+
switch (_context3.prev = _context3.next) {
|
|
121
|
+
case 0:
|
|
122
|
+
CONTAINER_ID = 'container-id';
|
|
123
|
+
ID = 'testId';
|
|
124
|
+
FIELD_ID = 'fieldId';
|
|
125
|
+
LABEL = 'Test label';
|
|
126
|
+
VALUE = 'nestedValue';
|
|
127
|
+
PARENT_CONFIG = {
|
|
128
|
+
onChange: function onChange() {},
|
|
129
|
+
formData: _defineProperty({}, CONTAINER_ID, _defineProperty({}, FIELD_ID, VALUE)),
|
|
130
|
+
full_path: "".concat(CONTAINER_ID, ".").concat(FIELD_ID)
|
|
131
|
+
};
|
|
132
|
+
NESTED_CONFIG = [{
|
|
133
|
+
id: ID,
|
|
134
|
+
fieldId: FIELD_ID,
|
|
135
|
+
label: LABEL,
|
|
136
|
+
type: 'text'
|
|
137
|
+
}];
|
|
138
|
+
_renderWithValidation2 = (0, _setupTests.renderWithValidation)((0, _getComponent.getChildrenJsx)(PARENT_CONFIG, NESTED_CONFIG)), container = _renderWithValidation2.container;
|
|
139
|
+
child = container.childNodes[0];
|
|
140
|
+
expect(child.childNodes.length).toEqual(3);
|
|
141
|
+
expect(child.classList).toContain('govuk-form-group');
|
|
142
|
+
label = child.childNodes[0];
|
|
143
|
+
expect(label).toBeDefined();
|
|
144
|
+
expect(label.innerHTML).toContain(LABEL);
|
|
145
|
+
input = child.childNodes[2];
|
|
146
|
+
expect(input.tagName).toEqual('INPUT');
|
|
147
|
+
expect(input.classList).toContain('govuk-input');
|
|
148
|
+
expect(input.id).toEqual("".concat(CONTAINER_ID, ".").concat(FIELD_ID));
|
|
149
|
+
expect(input.value).toEqual(VALUE);
|
|
150
|
+
|
|
151
|
+
case 19:
|
|
152
|
+
case "end":
|
|
153
|
+
return _context3.stop();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}, _callee3);
|
|
157
|
+
})));
|
|
158
|
+
it('should correctly set the value of the nested component within a collection', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
|
|
159
|
+
var COLLECTION_ID, ID, FIELD_ID, LABEL, VALUE, PARENT_CONFIG, NESTED_CONFIG, _renderWithValidation3, container, child, label, input;
|
|
160
|
+
|
|
161
|
+
return regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
162
|
+
while (1) {
|
|
163
|
+
switch (_context4.prev = _context4.next) {
|
|
164
|
+
case 0:
|
|
165
|
+
COLLECTION_ID = 'collection-id';
|
|
166
|
+
ID = 'testId';
|
|
167
|
+
FIELD_ID = 'fieldId';
|
|
168
|
+
LABEL = 'Test label';
|
|
169
|
+
VALUE = 'nestedValue';
|
|
170
|
+
PARENT_CONFIG = {
|
|
171
|
+
onChange: function onChange() {},
|
|
172
|
+
formData: _defineProperty({}, COLLECTION_ID, [_defineProperty({}, FIELD_ID, VALUE)]),
|
|
173
|
+
full_path: "".concat(COLLECTION_ID, "[0].").concat(FIELD_ID)
|
|
174
|
+
};
|
|
175
|
+
NESTED_CONFIG = [{
|
|
176
|
+
id: ID,
|
|
177
|
+
fieldId: FIELD_ID,
|
|
178
|
+
label: LABEL,
|
|
179
|
+
type: 'text'
|
|
180
|
+
}];
|
|
181
|
+
_renderWithValidation3 = (0, _setupTests.renderWithValidation)((0, _getComponent.getChildrenJsx)(PARENT_CONFIG, NESTED_CONFIG)), container = _renderWithValidation3.container;
|
|
182
|
+
child = container.childNodes[0];
|
|
183
|
+
expect(child.childNodes.length).toEqual(3);
|
|
184
|
+
expect(child.classList).toContain('govuk-form-group');
|
|
185
|
+
label = child.childNodes[0];
|
|
186
|
+
expect(label).toBeDefined();
|
|
187
|
+
expect(label.innerHTML).toContain(LABEL);
|
|
188
|
+
input = child.childNodes[2];
|
|
189
|
+
expect(input.tagName).toEqual('INPUT');
|
|
190
|
+
expect(input.classList).toContain('govuk-input');
|
|
191
|
+
expect(input.id).toEqual("".concat(COLLECTION_ID, "[0].").concat(FIELD_ID));
|
|
192
|
+
expect(input.value).toEqual(VALUE);
|
|
193
|
+
|
|
194
|
+
case 19:
|
|
195
|
+
case "end":
|
|
196
|
+
return _context4.stop();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}, _callee4);
|
|
200
|
+
})));
|
|
115
201
|
});
|
|
@@ -44,7 +44,10 @@ var validateContainer = function validateContainer(container, outerData, formDat
|
|
|
44
44
|
if (Array.isArray(container.components)) {
|
|
45
45
|
var containerData = outerData && container.fieldId ? outerData[container.fieldId] : outerData;
|
|
46
46
|
container.components.forEach(function (component) {
|
|
47
|
-
|
|
47
|
+
// It is possible that the container being passed in is a
|
|
48
|
+
// dummy container just for validation. In that scenario we want
|
|
49
|
+
// to ignore the full_path and just use the component's fieldId.
|
|
50
|
+
var full_path = container.full_path || container.fieldId ? "".concat(container.full_path || container.fieldId, ".").concat(component.fieldId) : component.fieldId;
|
|
48
51
|
errors.push((0, _validateComponent.default)(_objectSpread(_objectSpread({}, component), {}, {
|
|
49
52
|
full_path: full_path
|
|
50
53
|
}), containerData, fd));
|