Class: GOVUKDesignSystemFormBuilder::Elements::CollectionSelect

Inherits:
Base
  • Object
show all
Includes:
Traits::Error, Traits::HTMLAttributes, Traits::Hint, Traits::Label, Traits::Select, Traits::Supplemental
Defined in:
lib/govuk_design_system_formbuilder/elements/collection_select.rb

Instance Method Summary collapse

Methods included from Traits::HTMLAttributes

#attributes

Methods included from Traits::Supplemental

#supplemental_id

Methods included from Traits::Hint

#hint_id

Methods included from Traits::Error

#error_id

Methods inherited from Base

#field_id, #to_s

Constructor Details

#initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, hint:, label:, caption:, form_group:, options: {}, **kwargs, &block) ⇒ CollectionSelect

Returns a new instance of CollectionSelect.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/govuk_design_system_formbuilder/elements/collection_select.rb', line 11

def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, hint:, label:, caption:, form_group:, options: {}, **kwargs, &block)
  super(builder, object_name, attribute_name, &block)

  @collection      = collection
  @value_method    = value_method
  @text_method     = text_method
  @options         = options
  @label           = label
  @caption         = caption
  @hint            = hint
  @form_group      = form_group
  @html_attributes = kwargs

  # FIXME remove this soon, worth informing people who miss the release notes that the
  #       args have changed though.
  if :html_options.in?(kwargs.keys)
    warn("GOVUKDesignSystemFormBuilder: html_options has been deprecated, use keyword arguments instead")
  end
end

Instance Method Details

#htmlObject



31
32
33
34
35
# File 'lib/govuk_design_system_formbuilder/elements/collection_select.rb', line 31

def html
  Containers::FormGroup.new(*bound, **@form_group).html do
    safe_join([label_element, supplemental_content, hint_element, error_element, collection_select])
  end
end