Class: GOVUKDesignSystemFormBuilder::Elements::Select

Inherits:
Base
  • Object
show all
Includes:
Traits::Error, Traits::Hint, Traits::Label, Traits::Supplemental
Defined in:
lib/govuk_design_system_formbuilder/elements/select.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:, options: {}, html_options: {}, hint_text:, label:, &block) ⇒ Select

Returns a new instance of Select.


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

def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, options: {}, html_options: {}, hint_text:, label:, &block)
  super(builder, object_name, attribute_name, &block)

  @collection    = collection
  @value_method  = value_method
  @text_method   = text_method
  @options       = options
  @html_options  = html_options
  @label         = label
  @hint_text     = hint_text
end

Instance Method Details

#htmlObject


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/govuk_design_system_formbuilder/elements/select.rb', line 21

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.collection_select(
          @attribute_name,
          @collection,
          @value_method,
          @text_method,
          @options,
          build_html_options
        )
      ]
    )
  end
end