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

Inherits:
CCS::Components::GovUK::Field::Inputs show all
Defined in:
lib/ccs/components/govuk/field/inputs/date_input.rb,
lib/ccs/components/govuk/field/inputs/date_input/item.rb

Overview

GOV.UK Date Input

This is used for generating the date input component from the GDS - Components - Date Input

Defined Under Namespace

Classes: Item

Constant Summary collapse

DEFAULT_ATTRIBUTES =

The default attributes for the date input

{ class: 'govuk-date-input' }.freeze

Instance Method Summary collapse

Methods inherited from CCS::Components::GovUK::Field::Inputs

#render

Methods inherited from CCS::Components::GovUK::Field

#render

Constructor Details

#initialize(attribute:, date_items: nil, **options) ⇒ DateInput

Returns a new instance of DateInput.

Parameters:

  • date_items (Array<Hash>) (defaults to: nil)

    an array of options for the date items. See Item#initialize for details of the items in the array.

  • fieldset (Hash)

    attributes for the fieldset, see Fieldset#initialize for more details.

  • attribute (String, Symbol)

    the attribute of the field

  • hint (Hash)

    attributes for the hint, see Hint#initialize for more details. If no hint is given then no hint will be rendered

  • form_group (Hash)

    attributes for the form group, see FormGroup#initialize for more details.

  • options (Hash)

    options that will be used for the parts of the field

Options Hash (**options):

  • :error_message (String) — default: nil

    the error message to be displayed

  • :model (ActiveModel) — default: nil

    optional model that can be used to find an error message

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

    optional form builder used to create the field and find the error message

  • :classes (String)

    additional CSS classes for the field HTML

  • :attributes (Hash) — default: {}

    any additional attributes that will added as part of the HTML



21
22
23
24
25
26
27
28
29
# File 'lib/ccs/components/govuk/field/inputs/date_input.rb', line 21

def initialize(attribute:, date_items: nil, **options)
  (options[:fieldset][:attributes] ||= {})[:role] = 'group' if options[:fieldset]

  super(attribute: attribute, **options)

  date_items = default_date_items if date_items.blank?

  @input_items = date_items.map { |date_input_item| Item.new(attribute: attribute, error_message: @error_message, model: @options[:model], form: @options[:form], context: @context, **date_input_item) }
end