%
id_prefix ||= "radio-#{SecureRandom.hex(4)}"
items ||= []
label ||= nil
heading ||= nil
is_page_heading ||= false
hint ||= nil
error_message ||= nil
error_items ||= nil
has_error = error_message || error_items&.any?
hint_id = "hint-#{SecureRandom.hex(4)}" if hint
error_id = "error-#{SecureRandom.hex(4)}"
form_group_css_classes = %w(govuk-form-group)
form_group_css_classes << "govuk-form-group--error" if has_error
aria = "#{hint_id} #{"#{error_id}" if has_error}".strip if hint or has_error
# check if any item is set as being conditional
has_conditional = items.any? { |item| item.is_a?(Hash) && item[:conditional] }
%>
<%= content_tag :div, class: form_group_css_classes do %>
<%= tag.fieldset class: "govuk-fieldset", "aria-describedby": aria do %>
<% if heading.present? %>
<% if is_page_heading %>
<%= tag.legend class: "govuk-fieldset__legend govuk-fieldset__legend--xl gem-c-title gem-c-title--margin-bottom-5" do %>
<%= tag.h1 heading, class: "gem-c-title__text" %>
<% end %>
<% else %>
<%= tag.legend heading, class: "govuk-fieldset__legend govuk-fieldset__legend--m" %>
<% end %>
<% end %>
<% if hint %>
<%= render "govuk_publishing_components/components/hint", {
id: hint_id,
text: hint
} %>
<% end %>
<% if error_message %>
<%= render "govuk_publishing_components/components/error_message", {
id: error_id,
text: error_message
} %>
<% elsif error_items %>
<%= render "govuk_publishing_components/components/error_message", {
id: error_id,
text: raw(error_items.map { |item| item[:text] }.join("
"))
} %>
<% end %>
<%= content_tag :div, class: "govuk-radios",
data: {
module: ('radios' if has_conditional)
} do %>
<% items.each_with_index do |item, index| %>
<% if item === :or %>