Sha256: 897cd87c401766682aaafd7208390128a39de2c7083f6b026f0e9e1129cdc193

Contents?: true

Size: 1.48 KB

Versions: 4

Compression:

Stored size: 1.48 KB

Contents

<%
  id ||= "input-#{SecureRandom.hex(4)}"
  value ||= nil
  type ||= "text"
  describedby ||= false

  label ||= nil
  hint ||= nil
  error_message ||= nil
  hint_id = "hint-#{SecureRandom.hex(4)}" if hint
  error_message_id = "error-message-#{SecureRandom.hex(4)}" if error_message

  css_classes = %w(gem-c-input govuk-input)
  css_classes << "govuk-input--error" if error_message
  form_group_css_classes = %w(govuk-form-group)
  form_group_css_classes << "govuk-form-group--error" if error_message

  aria_described_by ||= nil
  if hint || error_message || describedby
    aria_described_by = []
    aria_described_by << hint_id if hint
    aria_described_by << error_message_id if error_message
    aria_described_by << describedby if describedby
    aria_described_by = aria_described_by.join(" ")
  end

%>

<%= content_tag :div, class: form_group_css_classes do %>
  <% if label %>
    <%= render "govuk_publishing_components/components/label", {
      text: label[:text],
      html_for: id
    } %>
  <% 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_message_id,
      text: error_message
    } %>
  <% end %>

  <%= text_field_tag name,
    value,
    {
      class: css_classes,
      id: id,
      type: type,
      aria: {
        describedby: aria_described_by
      }
    }
  %>
<% end %>

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
govuk_publishing_components-9.10.0 app/views/govuk_publishing_components/components/_input.html.erb
govuk_publishing_components-9.9.1 app/views/govuk_publishing_components/components/_input.html.erb
govuk_publishing_components-9.9.0 app/views/govuk_publishing_components/components/_input.html.erb
govuk_publishing_components-9.8.0 app/views/govuk_publishing_components/components/_input.html.erb