Skip to content

Commit

Permalink
Only query radios that are within the same form
Browse files Browse the repository at this point in the history
By doing this alongside checking the name we only run setAttributes on
the radio inputs that could change.
  • Loading branch information
NickColley committed Jul 16, 2019
1 parent 8967a1b commit dae265e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/govuk/components/radios/radios.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ Radios.prototype.setAttributes = function ($input) {
}

Radios.prototype.handleClick = function (event) {
var $clickedInput = event.target
// We only want to handle clicks for radio inputs
if (event.target.type !== 'radio') {
if ($clickedInput.type !== 'radio') {
return
}
// Because checking one radio can uncheck a radio in another $module,
// we need to call set attributes on all radios in the document
// we need to call set attributes on all radios in the form owner
//
// We also only want radios which have aria-controls, as they support conditional reveals.
var $allInputs = document.querySelectorAll('input[type="radio"][aria-controls]')
var $clickedInput = event.target
var $allInputs = $clickedInput.form.querySelectorAll('input[type="radio"][aria-controls]')
nodeListForEach($allInputs, function ($input) {
// In radios, only radios with the same name will affect each other.
if ($clickedInput.name === $input.name) {
Expand Down

0 comments on commit dae265e

Please sign in to comment.