Skip to content

Commit

Permalink
Always initialise modules on radios
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
36degrees authored and lfdebrux committed Jul 30, 2021
1 parent 5498f68 commit 1bb86f6
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions src/govuk/components/radios/template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@
aria-describedby – for example hints or error messages -#}
{% set describedBy = params.fieldset.describedBy if params.fieldset.describedBy else "" %}

{% set isConditional = false %}
{% for item in params.items %}
{% if item.conditional.html %}
{% set isConditional = true %}
{% endif %}
{% endfor %}

{#- Capture the HTML so we can optionally nest it in a fieldset -#}
{% set innerHtml %}
{% if params.hint %}
Expand Down Expand Up @@ -45,7 +38,7 @@
{% endif %}
<div class="govuk-radios {%- if params.classes %} {{ params.classes }}{% endif %}{%- if isConditional %} govuk-radios--conditional{% endif -%}"
{%- for attribute, value in params.attributes %} {{ attribute }}="{{ value }}"{% endfor %}
{%- if isConditional %} data-module="govuk-radios"{% endif -%}>
data-module="govuk-radios">
{% for item in params.items %}
{% if item %}
{#- If the user explicitly sets an id, use this instead of the regular idPrefix -#}
Expand Down

0 comments on commit 1bb86f6

Please sign in to comment.