Class: UiBibzInputs::UiChoiceGroupInput

Inherits:
CollectionInput
  • Object
show all
Includes:
UiBibz::Ui::Core::Forms::Choices
Defined in:
lib/ui_bibz/inputs/ui_bibz_inputs/ui_choice_group_input.rb

Instance Method Summary collapse

Methods inherited from CollectionInput

#collection, #group_label_method, #group_method, #grouped_collection, #input_attribute_name, #input_html_options, #new_options, #new_value

Instance Method Details

#input(wrapper_options = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ui_bibz/inputs/ui_bibz_inputs/ui_choice_group_input.rb', line 7

def input(wrapper_options = nil)
  label_method, value_method = detect_collection_methods # rubocop:disable Lint/UselessAssignment

  merged_input_options = merge_wrapper_options(input_html_options, wrapper_options) # rubocop:disable Lint/UselessAssignment

  UiBibz::Ui::Core::Forms::Choices::ChoiceGroup.new(input_options).tap do |bc|
    collection.each do |item|
      opts = { name: "#{@builder.object.class.name.underscore}[#{attribute_name}]", value: item[1] }
      opts = opts.merge({ state: :active }) if @builder.object.send(attribute_name).to_s == item[1].to_s
      bc.button item[0], opts
    end
  end.render
end