Sha256: 24b54042923b6f3096cebb80d0bbc73e1ded51e6b5b40f3761501c90458cc9aa
Contents?: true
Size: 1.31 KB
Versions: 2
Compression:
Stored size: 1.31 KB
Contents
class DropdownSelectInput < SimpleForm::Inputs::CollectionInput include ActionView::Helpers::TagHelper include ActionView::Context def current_value input_html_options[:value] || object.try(:send, attribute_name) end def selected_option if current_value collection.find { |x| x[1] == current_value } else collection.first end end def input(wrapper_options = nil) if options[:allow_blank] collection.unshift( [options[:allow_blank] == true ? 'None' : options[:allow_blank], ''] ) end content_tag(:div, class: 'styled_select_wrapper', 'data-dropdown-select' => true) do @builder.hidden_field(attribute_name, input_html_options) + content_tag(:div, class: 'styled_select', '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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
simple_form-dropdown_select-0.2.1 | app/inputs/dropdown_select_input.rb |
simple_form-dropdown_select-0.2.0 | app/inputs/dropdown_select_input.rb |