Class: GOVUKDesignSystemFormBuilder::Elements::File

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

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, hint_text:, label:, **extra_args, &block) ⇒ File

Returns a new instance of File.


9
10
11
12
13
14
15
# File 'lib/govuk_design_system_formbuilder/elements/file.rb', line 9

def initialize(builder, object_name, attribute_name, hint_text:, label:, **extra_args, &block)
  super(builder, object_name, attribute_name, &block)

  @label      = label
  @hint_text  = hint_text
  @extra_args = extra_args
end

Instance Method Details

#htmlObject


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

def html
  Containers::FormGroup.new(@builder, @object_name, @attribute_name).html do
    safe_join(
      [
        label_element.html,
        hint_element.html,
        error_element.html,
        supplemental_content.html,
        @builder.file_field(
          @attribute_name,
          id: field_id(link_errors: true),
          class: file_classes,
          aria: { describedby: described_by(hint_id, error_id, supplemental_id) },
          **@extra_args
        )
      ]
    )
  end
end