Sha256: 807fb392a0033b2c5172b6a3f3bb1e992d17eb004cddd2a5c041329b97519e48

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

class DropdownSelectInput < SimpleForm::Inputs::CollectionInput

  include ActionView::Helpers::TagHelper
  include ActionView::Context

  def selected_option
    collection.find { |x| x[1] == object.send(attribute_name) }
  end

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

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

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simple_form-dropdown_select-0.1.1 app/inputs/dropdown_select_input.rb