govuk_publishing_components 61.1.0 → 61.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 34fc86f0b6984bcd2bb2d4669470ff8268cdc8fedb85addeef526236c3f5abcf
4
- data.tar.gz: db1347382632d01113fe792d9b2b4b42758417ea2b2a6aeb8fec94dc73d9c8ef
3
+ metadata.gz: ee652fec945b78a8ab3380d6c93010e71a7dde1e1abcde77c69996245f608b53
4
+ data.tar.gz: d3de57ce6e16dfaacff00e7d129c2c748d4043b825b76b04fd8087f794435104
5
5
  SHA512:
6
- metadata.gz: fe96b53f6e688e0b36555eaeda6ac50b7c9760d4db8db8519920b5d3e07fc59046ec8bdb9a4477f671182ac9820ec4ed16006e4edb9552dd5b3f68b09a2cff9c
7
- data.tar.gz: 735c8823a24e2d7de30b3874886bb0a21b39cce18c9bb02daa197834ae4e8912ce9671b64b03c1e3d5d94420ea79037ce35df4768e8deb15fb4343110b898027
6
+ metadata.gz: f462ec25f4372596b7d914a9469aba1b5ee139b0da5dce07c00362373967ecb4fc5f2cfa9775d6bfa702ff23a971cb9cceccdbc4280d7ff982bfcd94779105ad
7
+ data.tar.gz: b585086d2a8d4a75a0a2769dd47051c701e7d6d3347664c56a659168ecc09b0871f611ee9ac2e6aa484a4b869a226787bf93d252228b4301a66af6db848fe3be
@@ -110,16 +110,10 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
110
110
 
111
111
  var isTextField = inputTypes.indexOf(inputType) !== -1 || inputNodename === 'TEXTAREA'
112
112
  var conditionalField = elem.closest('.govuk-checkboxes__conditional')
113
- var conditionalCheckbox = conditionalField && conditionalField.querySelector('[aria-controls="' + conditionalField.id + '"]')
113
+ var conditionalCheckbox = conditionalField && this.module.querySelector('[aria-controls="' + conditionalField.id + '"]')
114
114
  var conditionalCheckboxChecked = conditionalCheckbox && conditionalCheckbox.checked
115
115
 
116
- if (conditionalField && conditionalCheckboxChecked) {
117
- var conditionalCheckboxLabel = conditionalField.querySelector('[for="' + conditionalCheckbox.id + '"]')
118
-
119
- if (conditionalCheckboxLabel) {
120
- input.parentSection = conditionalCheckboxLabel.innerText
121
- }
122
- }
116
+ var isDateField = elem.closest('.govuk-date-input')
123
117
 
124
118
  if (conditionalCheckbox && !conditionalCheckboxChecked) {
125
119
  // don't include conditional field if condition not checked
@@ -141,10 +135,16 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
141
135
  }
142
136
  } else if (inputNodename === 'SELECT' && elem.querySelectorAll('option:checked')) {
143
137
  var selectedOptions = Array.from(elem.querySelectorAll('option:checked')).map(function (element) { return element.text })
144
- input.answer = this.useSelectCount ? selectedOptions.length : selectedOptions.join(',')
138
+
139
+ if (selectedOptions.length === 1 && !elem.value.length) {
140
+ // if placeholder value in select, do not include as not filled in
141
+ inputs.splice(i, 1)
142
+ } else {
143
+ input.answer = this.useSelectCount && selectedOptions.length > 1 ? selectedOptions.length : selectedOptions.join(',')
144
+ }
145
145
  } else if (isTextField && elem.value) {
146
146
  if (this.includeTextInputValues || elem.hasAttribute('data-ga4-form-include-input')) {
147
- if (this.useTextCount) {
147
+ if (this.useTextCount && !isDateField) {
148
148
  input.answer = elem.value.length
149
149
  } else {
150
150
  var PIIRemover = new window.GOVUK.analyticsGa4.PIIRemover()
@@ -163,6 +163,32 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
163
163
  // remove the input from those gathered as it has no value
164
164
  inputs.splice(i, 1)
165
165
  }
166
+
167
+ var parentFieldset
168
+ var parentLegend
169
+
170
+ if (conditionalField && conditionalCheckboxChecked) {
171
+ parentFieldset = conditionalField.closest('fieldset')
172
+ parentLegend = parentFieldset && parentFieldset.querySelector('legend')
173
+
174
+ if (parentLegend) {
175
+ input.section = parentLegend.innerText + ' - ' + input.section
176
+ }
177
+ } else if (isDateField) {
178
+ var dateFieldset = elem.closest('.govuk-date-input').closest('fieldset')
179
+ var dateLegend = dateFieldset && dateFieldset.querySelector('legend')
180
+
181
+ parentFieldset = dateFieldset.parentNode.closest('fieldset')
182
+
183
+ if (dateLegend) {
184
+ input.section = dateLegend.innerText + ' - ' + input.section
185
+ }
186
+
187
+ if (parentFieldset) {
188
+ parentLegend = parentFieldset.querySelector('legend')
189
+ input.section = parentLegend.innerText + ' - ' + input.section
190
+ }
191
+ }
166
192
  }
167
193
  return inputs
168
194
  }
@@ -176,17 +202,10 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
176
202
  if (answer) {
177
203
  if (this.recordJson) {
178
204
  var fieldSection = data[i].section
179
- var parentFieldSection = data[i].parentSection
180
205
 
181
206
  if (fieldSection) {
182
- if (parentFieldSection) {
183
- answers[parentFieldSection] = answers[parentFieldSection] || {}
184
- answers[parentFieldSection][fieldSection] = answers[parentFieldSection][fieldSection] || ''
185
- answers[parentFieldSection][fieldSection] += ((answers[parentFieldSection][fieldSection] ? ',' : '') + answer)
186
- } else {
187
- answers[fieldSection] = answers[fieldSection] || ''
188
- answers[fieldSection] += ((answers[fieldSection] ? ',' : '') + answer)
189
- }
207
+ answers[fieldSection] = answers[fieldSection] ? (answers[fieldSection] + ',') : ''
208
+ answers[fieldSection] += answer
190
209
  }
191
210
  } else {
192
211
  answers.push(answer)
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "61.1.0".freeze
2
+ VERSION = "61.1.1".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_publishing_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 61.1.0
4
+ version: 61.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev