Class: GOVUKDesignSystemFormBuilder::Elements::Radios::Collection

Inherits:
Base
  • Object
show all
Includes:
Traits::Error, Traits::Hint, Traits::Supplemental
Defined in:
lib/govuk_design_system_formbuilder/elements/radios/collection.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, collection, value_method:, text_method:, hint_method:, hint_text:, legend:, inline:, small:, bold_labels:, classes:, &block) ⇒ Collection

Returns a new instance of Collection.


9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/govuk_design_system_formbuilder/elements/radios/collection.rb', line 9

def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, hint_method:, hint_text:, legend:, inline:, small:, bold_labels:, classes:, &block)
  super(builder, object_name, attribute_name, &block)

  @collection    = collection
  @value_method  = value_method
  @text_method   = text_method
  @hint_method   = hint_method
  @inline        = inline
  @small         = small
  @legend        = legend
  @hint_text     = hint_text
  @classes       = classes
  @bold_labels   = hint_method.present? || bold_labels
end

Instance Method Details

#htmlObject


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/govuk_design_system_formbuilder/elements/radios/collection.rb', line 24

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,
          Containers::Radios.new(@builder, inline: @inline, small: @small, classes: @classes).html do
            safe_join(build_collection)
          end
        ]
      )
    end
  end
end