@gov-cy/govcy-express-services 1.6.1 โ†’ 1.6.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gov-cy/govcy-express-services",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
4
4
  "description": "An Express-based system that dynamically renders services using @gov-cy/govcy-frontend-renderer and posts data to a submission API.",
5
5
  "author": "DMRID - DSF Team",
6
6
  "license": "MIT",
@@ -101,11 +101,19 @@ export function prepareSubmissionData(req, siteId, service) {
101
101
  // radios conditional elements
102
102
  if (el.element === "radios") {
103
103
  for (const radioItem of el.params.items || []) {
104
+
105
+ const isSelected = radioItem.value === value; // ๐Ÿ”ธ to decide to populate only selected
106
+
104
107
  for (const condEl of radioItem.conditionalElements || []) {
105
108
  if (!ALLOWED_FORM_ELEMENTS.includes(condEl.element)) continue;
106
109
  const condId = condEl.params?.id || condEl.params?.name;
107
110
  if (!condId) continue;
108
- let condValue = getValue(condEl, pageUrl, req, siteId, idx);
111
+
112
+ // ๐Ÿ”ธonly populate if selected, otherwise empty string
113
+ let condValue = isSelected
114
+ ? getValue(condEl, pageUrl, req, siteId, idx)
115
+ : ""; // ๐Ÿ”ธ Empty if conditional radio is not selected
116
+
109
117
  itemData[condId] = condValue;
110
118
 
111
119
  if (condEl.element === "fileInput") {
@@ -156,6 +164,8 @@ export function prepareSubmissionData(req, siteId, service) {
156
164
  const condEls = radioItem.conditionalElements;
157
165
  if (!Array.isArray(condEls)) continue;
158
166
 
167
+ const isSelected = radioItem.value === value; // ๐Ÿ”ธ to decide to populate only selected
168
+
159
169
  for (const condElement of condEls) {
160
170
  const condType = condElement.element;
161
171
  if (!ALLOWED_FORM_ELEMENTS.includes(condType)) continue;
@@ -164,7 +174,10 @@ export function prepareSubmissionData(req, siteId, service) {
164
174
  if (!condId) continue;
165
175
 
166
176
  // Again: read from session or fallback to ""
167
- const condValue = getValue(condElement, pageUrl, req, siteId) ?? "";
177
+ // ๐Ÿ”ธ only populate if selected; otherwise keep empty string
178
+ const condValue = isSelected
179
+ ? getValue(condElement, pageUrl, req, siteId) ?? ""
180
+ : ""; // ๐Ÿ”ธ Empty if conditional radio is not selected
168
181
 
169
182
  // Store even if the field was not visible to user
170
183
  // submissionData[pageUrl].formData[condId] = condValue;