Class: GOVUKDesignSystemFormBuilder::Elements::CheckBoxes::CollectionCheckBox

Inherits:
Base
  • Object
show all
Includes:
Traits::CollectionItem, Traits::Hint
Defined in:
lib/govuk_design_system_formbuilder/elements/check_boxes/collection_check_box.rb

Instance Method Summary collapse

Methods included from Traits::Hint

#hint_id

Methods inherited from Base

#field_id, #to_s

Constructor Details

#initialize(builder, object_name, attribute_name, checkbox, hint_method = nil, link_errors: false) ⇒ CollectionCheckBox

Returns a new instance of CollectionCheckBox.



8
9
10
11
12
13
14
15
16
# File 'lib/govuk_design_system_formbuilder/elements/check_boxes/collection_check_box.rb', line 8

def initialize(builder, object_name, attribute_name, checkbox, hint_method = nil, link_errors: false)
  super(builder, object_name, attribute_name)

  @checkbox    = checkbox
  @item        = checkbox.object
  @value       = checkbox.value
  @hint        = { text: retrieve(@item, hint_method) }
  @link_errors = link_errors
end

Instance Method Details

#htmlObject



18
19
20
21
22
# File 'lib/govuk_design_system_formbuilder/elements/check_boxes/collection_check_box.rb', line 18

def html
  tag.div(class: %(#{brand}-checkboxes__item)) do
    safe_join([check_box, label_element, hint_element])
  end
end