Class: DropdownSelectInput

Inherits:
SimpleForm::Inputs::CollectionInput
  • Object
show all
Includes:
ActionView::Context, ActionView::Helpers::TagHelper
Defined in:
app/inputs/dropdown_select_input.rb

Instance Method Summary collapse

Instance Method Details

#current_valueObject



6
7
8
# File 'app/inputs/dropdown_select_input.rb', line 6

def current_value
  input_html_options[:value] || object.try(:send, attribute_name)
end

#input(wrapper_options = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/inputs/dropdown_select_input.rb', line 18

def input(wrapper_options = nil)
  if options[:allow_blank]
    collection.unshift(
      [options[:allow_blank] == true ? 'None' : options[:allow_blank], '']
    )
  end

  (:div, class: 'styled_select_wrapper', 'data-dropdown-select' => true) do
    @builder.hidden_field(attribute_name, input_html_options) +
    (:div, class: 'styled_select', 'data-toggle' => 'dropdown') { selected_option[0] } +
    (:div, class: 'dropdown_menu dropdown_menu_rich') {
      (:ul, class: 'dropdown_body') {
        collection.map do |x|
          (:li, class: selected_option == x ? 'active' : nil) {
            (:a, 'data-value' => x[1]) {
              (:strong, class: 'drop_rich_head') { x[0] } +
              (:span, class: 'drop_rich_subhead') { x[2] }
            }
          }
        end.join('').html_safe
      }
    }
  end
end

#selected_optionObject



10
11
12
13
14
15
16
# File 'app/inputs/dropdown_select_input.rb', line 10

def selected_option
  if current_value
    collection.find { |x| x[1] == current_value }
  else
    collection.first
  end
end