-
Notifications
You must be signed in to change notification settings - Fork 333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent conditionally revealed questions getting out of sync when multiple sets of radios and checkboxes contain inputs with the same name #2255
Conversation
Should we include this in 3.13.0 or hold this and merge after the release has gone out? We have 'frozen' the release, but arguably these are things that could have been fixed as part of #2151. Equally, these are existing bugs that are unlikely to come up in most contexts. |
I vote for holding! |
Hmm, testing the new examples with VoiceOver in Safari I found that the |
var $target = document.querySelector('#' + $input.getAttribute('aria-controls')) | ||
var $target = document.getElementById($input.getAttribute('aria-controls')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙌 🙌 🙌
I think it might be good to have tests for this behaviour to catch possible future regressions; something like 32f116d for example? |
I've realised that the (necessary) change from Attached to the 4.0 milestone. |
32f116d
to
7c3dd77
Compare
7c3dd77
to
6ad421d
Compare
@36degrees I've added more tests in 6ad421d, I think covering everything this PR fixes. I have run these tests before the fixes and they fail as expected, so I think they should make good regression tests. Feel free to leave comments/suggestions on them! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍 Think it just needs a changelog entry?
6ad421d
to
b4b8541
Compare
We have an open issue to provide examples of grouping radios and checkboxes under headings (#1079). Whilst we don’t provide any guidance on this at the minute, we’ve previously suggested that users can achieve this by making multiple calls to the `govukCheckboxes` macro and grouping them together inside a single call to `govukFieldset`. However, this means that each ‘set’ of checkboxes is inside its own module, which can cause issues with things like conditional reveals. Add an example of this to the review app, so that we can test that everything works as expected.
Rather than calling `this.syncAllConditionalReveals`, which only syncs conditional reveals on checkboxes within the same module, sync every conditional reveal with the same name and form owner during the the existing loop. When syncing each conditional reveal, we also need to look for the targeted element across the entire document, as we might be syncing a conditional reveal outside of the current module. We can also simplify the lookup by using document.getElementById rather than using querySelector which requires us to manually prepend the hash to get an ID selector.
This matches a change previously made to the checkboxes component in 7e746b4. If you use two separate calls to the macro with the same name, but one of them does not contain any radios with conditional reaveals, then checking a radio in that list would not hide a conditional reveal in the other list, as the module has not been initialised so no `eventListener` has been set up. Always initialise the javascript for every set of radios which solves this issue.
Use document.getElementById rather than document.querySelector which requires us to manually prepend the hash to get an ID selector.
Adds tests for JavaScript behaviours we want to work across separate groups of radios or checkboxes with the same `name`, specifically: - conditional reveals - 'none of the above' checkbox
b4b8541
to
8d9ce98
Compare
For some reason the GitHub Actions have not been triggered on the latest commit. Closing and re-opening to try and force them to run… |
data-module attribute now always present. See alphagov/govuk-frontend#2255 See also alphagov/govuk-frontend#2516
We have an open issue to provide examples of grouping radios and checkboxes under headings.
Whilst we don’t provide any guidance on this at the minute, we’ve previously suggested that users can achieve this by making multiple calls to the
govukCheckboxes
macro and grouping them together inside a single call togovukFieldset
. However, this means that each ‘set’ of checkboxes is inside its own module, which can cause issues with things like conditional reveals.Add an example of this to the review app, so that we can test that everything works as expected, and fix a few issues identified that can leave conditional reveals 'out of sync' with their controls in this context.
See individual commits for details.
Details of breaking change
Although technically this is a breaking change, it's the 'same' breaking change as in #2370. So I suggest we just include this in the list of 'Fixes'.