Class: GOVUKDesignSystemFormBuilder::Elements::CheckBoxes::Collection

Inherits:
Base
  • Object
show all
Includes:
Traits::Error, Traits::Hint, Traits::Supplemental
Defined in:
lib/govuk_design_system_formbuilder/elements/check_boxes/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: nil, hint_text:, legend:, small:, classes:, &block) ⇒ Collection

Returns a new instance of Collection.


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

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

  @collection    = collection
  @value_method  = value_method
  @text_method   = text_method
  @hint_method   = hint_method
  @small         = small
  @legend        = legend
  @hint_text     = hint_text
  @classes       = classes
end

Instance Method Details

#htmlObject


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

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