@ukhomeoffice/cop-react-form-renderer 5.3.0 → 5.5.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.
@@ -92,7 +92,12 @@ var CollectionPage = function CollectionPage(_ref) {
92
92
  };
93
93
  return /*#__PURE__*/_react.default.createElement(_FormPage.default, {
94
94
  page: _objectSpread(_objectSpread({}, page), {}, {
95
- formData: _objectSpread(_objectSpread(_objectSpread({}, page.formData), data[activeIndex]), {}, _defineProperty({}, "".concat(page.collection.name, "ActiveIndex"), activeIndex))
95
+ formData: _objectSpread(_objectSpread(_objectSpread({}, page.formData), data[activeIndex]), {}, _defineProperty({}, "".concat(page.collection.name, "ActiveIndex"), activeIndex)),
96
+ components: page.components.map(function (component) {
97
+ return _objectSpread(_objectSpread({}, component), {}, {
98
+ full_path: "".concat(page.collection.name, "[").concat(activeIndex, "].").concat(component.full_path || component.fieldId)
99
+ });
100
+ })
96
101
  }),
97
102
  onAction: onInnerPageAction,
98
103
  onWrapperChange: onInnerPageChange,
@@ -141,7 +141,7 @@ describe('components.CollectionPage', function () {
141
141
  expect(label.tagName).toEqual('LABEL');
142
142
  expect(label.classList).toContain('govuk-label');
143
143
  expect(label.textContent).toEqual(lbl);
144
- expect(label.getAttribute('for')).toEqual(fieldId);
144
+ expect(label.getAttribute('for')).toEqual("".concat(COLLECTION_NAME, "[0].").concat(fieldId));
145
145
  var hint = formGroup.childNodes[1];
146
146
  expect(hint.tagName).toEqual('DIV');
147
147
  expect(hint.classList).toContain('govuk-hint');
@@ -149,7 +149,7 @@ describe('components.CollectionPage', function () {
149
149
  var input = formGroup.childNodes[2];
150
150
  expect(input.tagName).toEqual('INPUT');
151
151
  expect(input.classList).toContain('govuk-input');
152
- expect(input.id).toEqual(fieldId);
152
+ expect(input.id).toEqual("".concat(COLLECTION_NAME, "[0].").concat(fieldId));
153
153
  expect(input.value).toEqual(val);
154
154
  return input;
155
155
  };
@@ -160,7 +160,7 @@ describe('components.CollectionPage', function () {
160
160
  expect(label.tagName).toEqual('LABEL');
161
161
  expect(label.classList).toContain('govuk-label');
162
162
  expect(label.textContent).toEqual(lbl);
163
- expect(label.getAttribute('for')).toEqual(fieldId);
163
+ expect(label.getAttribute('for')).toEqual("".concat(COLLECTION_NAME, "[0].").concat(fieldId));
164
164
  var hint = formGroup.childNodes[1];
165
165
  expect(hint.tagName).toEqual('DIV');
166
166
  expect(hint.classList).toContain('govuk-hint');
@@ -174,7 +174,7 @@ describe('components.CollectionPage', function () {
174
174
  })[0];
175
175
  expect(input.classList).toContain('hods-autocomplete__input');
176
176
  expect(input.tagName).toEqual('INPUT');
177
- expect(input.id).toEqual(fieldId);
177
+ expect(input.id).toEqual("".concat(COLLECTION_NAME, "[0].").concat(fieldId));
178
178
  expect(input.value).toEqual(val);
179
179
  return input;
180
180
  };
@@ -6,8 +6,11 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
8
8
  var setDataItem = function setDataItem(data, fieldId, value) {
9
+ var handleArrayIndices = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
9
10
  if (fieldId && data) {
10
- var parts = fieldId.split('.');
11
+ var parts = handleArrayIndices ?
12
+ // Replace all occurrences of '[' with '.' and ']' with ''.
13
+ fieldId.replace(/\[/g, '.').replace(/\]/g, '').split('.') : fieldId.split('.');
11
14
  var leaf = parts.pop();
12
15
  var node = data;
13
16
  parts.forEach(function (part) {
@@ -107,4 +107,29 @@ describe('utils.Data.setDataItem', function () {
107
107
  }
108
108
  });
109
109
  });
110
+ it('should handle array indices in fieldPath if handleArrayIndices is true', function () {
111
+ var DATA = {
112
+ alpha: {
113
+ bravo: [{
114
+ charlie: '123'
115
+ }]
116
+ }
117
+ };
118
+ var FIELD_ID = 'alpha.bravo[0].charlie';
119
+ var VALUE = '456';
120
+ expect((0, _setDataItem.default)(DATA, FIELD_ID, VALUE, true)).toMatchObject({
121
+ alpha: {
122
+ bravo: [{
123
+ charlie: VALUE
124
+ }]
125
+ }
126
+ });
127
+ expect(DATA).toMatchObject({
128
+ alpha: {
129
+ bravo: [{
130
+ charlie: VALUE
131
+ }]
132
+ }
133
+ });
134
+ });
110
135
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "5.3.0",
3
+ "version": "5.5.0",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",