Class: GOVUKDesignSystemFormBuilder::Elements::Date

Inherits:
Base
  • Object
show all
Includes:
Traits::Error, Traits::Hint, Traits::Supplemental
Defined in:
lib/govuk_design_system_formbuilder/elements/date.rb

Constant Summary collapse

SEGMENTS =
{ day: '3i', month: '2i', year: '1i' }.freeze

Instance Method Summary collapse

Methods included from Traits::Supplemental

#supplemental_id

Methods included from Traits::Hint

#hint_id

Methods included from Traits::Error

#error_id

Constructor Details

#initialize(builder, object_name, attribute_name, legend:, hint_text:, date_of_birth: false, omit_day:, &block) ⇒ Date

Returns a new instance of Date.


10
11
12
13
14
15
16
17
# File 'lib/govuk_design_system_formbuilder/elements/date.rb', line 10

def initialize(builder, object_name, attribute_name, legend:, hint_text:, date_of_birth: false, omit_day:, &block)
  super(builder, object_name, attribute_name, &block)

  @legend        = legend
  @hint_text     = hint_text
  @date_of_birth = date_of_birth
  @omit_day      = omit_day
end

Instance Method Details

#htmlObject


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/govuk_design_system_formbuilder/elements/date.rb', line 19

def html
  Containers::FormGroup.new(@builder, @object_name, @attribute_name).html do
    Containers::Fieldset.new(@builder, @object_name, @attribute_name, legend: @legend, described_by: [error_id, hint_id, supplemental_id]).html do
      safe_join(
        [
          hint_element.html,
          error_element.html,
          supplemental_content.html,
          ('div', class: 'govuk-date-input') do
            safe_join([day, month, year])
          end
        ]
      )
    end
  end
end