Sha256: 27b6c311d6adf009288b49692a363d1fe22d1557779ce8cb6eec6b90cf477622

Contents?: true

Size: 1.65 KB

Versions: 70

Compression:

Stored size: 1.65 KB

Contents

<%
  id ||= "file-upload-#{SecureRandom.hex(4)}"
  value ||= nil
  accept ||= nil
  data ||= nil

  label ||= nil
  hint ||= nil
  error_message ||= nil
  error_items ||= nil
  has_error = error_message || error_items&.any?
  hint_id = "hint-#{SecureRandom.hex(4)}"
  error_id = "error-#{SecureRandom.hex(4)}"

  css_classes = %w(gem-c-file-upload govuk-file-upload)
  css_classes << "govuk-file-upload--error" if has_error
  form_group_css_classes = %w(govuk-form-group)
  form_group_css_classes << "govuk-form-group--error" if has_error

  aria_described_by ||= nil
  if hint || has_error
    aria_described_by = []
    aria_described_by << hint_id if hint
    aria_described_by << error_id if has_error
    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", { html_for: id, text: label[:text] }.merge(label.symbolize_keys) %>
  <% 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("<br/>"))
    } %>
  <% end %>

  <%= tag.input name: name,
    type: "file",
    value: value,
    class: css_classes,
    id: id,
    data: data,
    accept: accept,
    aria: {
      describedby: aria_described_by
    } %>
<% end %>

Version data entries

70 entries across 70 versions & 1 rubygems

Version Path
govuk_publishing_components-12.16.0 app/views/govuk_publishing_components/components/_file_upload.html.erb
govuk_publishing_components-12.15.0 app/views/govuk_publishing_components/components/_file_upload.html.erb
govuk_publishing_components-12.14.1 app/views/govuk_publishing_components/components/_file_upload.html.erb
govuk_publishing_components-12.14.0 app/views/govuk_publishing_components/components/_file_upload.html.erb
govuk_publishing_components-12.13.0 app/views/govuk_publishing_components/components/_file_upload.html.erb
govuk_publishing_components-12.12.1 app/views/govuk_publishing_components/components/_file_upload.html.erb
govuk_publishing_components-12.12.0 app/views/govuk_publishing_components/components/_file_upload.html.erb
govuk_publishing_components-12.11.0 app/views/govuk_publishing_components/components/_file_upload.html.erb
govuk_publishing_components-12.10.0 app/views/govuk_publishing_components/components/_file_upload.html.erb
govuk_publishing_components-12.9.1 app/views/govuk_publishing_components/components/_file_upload.html.erb