Class: CCS::Components::GovUK::Field::Inputs::DateInput::Item

Inherits:
Object
  • Object
show all
Includes:
ActionView::Context, ActionView::Helpers
Defined in:
lib/ccs/components/govuk/field/inputs/date_input/item.rb

Overview

GOV.UK Date Inputs item

This is used to generate an individual date input item

Instance Method Summary collapse

Constructor Details

#initialize(attribute:, name:, context:, input: {}, label: {}, **options) ⇒ Item

Returns a new instance of Item.

Parameters:

  • attribute (String, Symbol)

    the attribute for the date inputs

  • name (String)

    the name of the date input item

  • input (Hash) (defaults to: {})

    options for the input of the date input item, see TextInput#initialize for more details.

  • label (Hash) (defaults to: {})

    options for the label of the date input item, see Label#initialize for more details.

  • context (ActionView::Base)

    the view context

  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • error_message (Hash)

    used as a flag to add the error classes to the item

  • :model (ActiveModel) — default: nil

    optional model used to create the field

  • :form (ActionView::Helpers::FormBuilder) — default: nil

    optional form builder used to create the field



39
40
41
42
43
44
45
46
47
48
# File 'lib/ccs/components/govuk/field/inputs/date_input/item.rb', line 39

def initialize(attribute:, name:, context:, input: {}, label: {}, **options)
  input[:classes] = "govuk-date-input__input #{input[:classes]}".rstrip
  input[:classes] << ' govuk-input--error' if options[:error_message]
  (input[:attributes] ||= {})[:inputmode] ||= 'numeric'

  label[:text] ||= name.capitalize
  label[:classes] = 'govuk-date-input__label'

  @input = Input::TextInput.new(attribute: "#{attribute}_#{name}", label: label, model: options[:model], form: options[:form], context: context, **input)
end

Instance Method Details

#renderActiveSupport::SafeBuffer

Generates the HTML for the date input item

Returns:

  • (ActiveSupport::SafeBuffer)


56
57
58
# File 'lib/ccs/components/govuk/field/inputs/date_input/item.rb', line 56

def render
  tag.div(input.render, class: 'govuk-date-input__item')
end