Sha256: 9d4799d14de7fd9fed83806343c61c29799e4036619ece112809a7b7b07e1f78

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

<%
  # Infer name and id_prefix from attribute key
  local_assigns[:name] ||= get_attribute_name(form, key)
  local_assigns[:idPrefix] ||= get_attribute_id_prefix(form, key)
  #Give items ids based on rails' convention
  local_assigns[:items].each do |item|
    #sanitization taken from https://github.com/rails/rails/
    #    blob/7caea98e189c02721b2e944a074c405b033852eb/actionview/lib/action_view/helpers/tags/base.rb#L140
    value = item[:value].to_s.gsub(/\s/, "_").gsub(/[^-[[:word:]]]/, "").mb_chars.downcase.to_s
    item[:id] ||= "#{local_assigns[:idPrefix]}_#{value}"
  end
  if form.object.respond_to?(key)
    # Make item checked based on attribute value
    item_matching_state = items.find do |item|
      !item[:divider] && item[:value].to_s == form.object.public_send(key).to_s
    end
    item_matching_state[:checked] = true if item_matching_state
  end
  unless form.object.nil?
    error_text = form.object.errors.full_messages_for(key).first.presence
    local_assigns[:errorMessage] ||= { text: error_text } if error_text
  end
%>
<%= render "components/govuk_radios", **local_assigns %>

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
govuk-design-system-rails-0.10.1 app/views/form_components/_govuk_radios.html.erb