Class: GOVUKDesignSystemFormBuilder::Elements::Radios::CollectionRadioButton

Inherits:
Base
  • Object
show all
Includes:
Traits::CollectionItem, Traits::Hint
Defined in:
lib/govuk_design_system_formbuilder/elements/radios/collection_radio_button.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, item, value_method:, text_method:, hint_method:, bold_labels:, link_errors: false) ⇒ CollectionRadioButton

Returns a new instance of CollectionRadioButton.

Parameters:

  • link_errors (Boolean) (defaults to: false)

    used to control the id generated for radio buttons. The error summary requires that the id of the first radio is linked-to from the corresponding error message. As when the summary is built what happens later in the form is unknown, we need to control this to ensure the link is generated correctly



12
13
14
15
16
17
18
19
20
21
# File 'lib/govuk_design_system_formbuilder/elements/radios/collection_radio_button.rb', line 12

def initialize(builder, object_name, attribute_name, item, value_method:, text_method:, hint_method:, bold_labels:, link_errors: false)
  super(builder, object_name, attribute_name)

  @item        = item
  @value       = retrieve(item, value_method)
  @label_text  = retrieve(item, text_method)
  @hint_text   = retrieve(item, hint_method)
  @link_errors = link_errors
  @bold_labels = bold_labels
end

Instance Method Details

#htmlObject



23
24
25
26
27
# File 'lib/govuk_design_system_formbuilder/elements/radios/collection_radio_button.rb', line 23

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