Sha256: fc915fa43796b7043cd8ea1cbdf4aa3fad7600c1e5b916c4181a096e090901d3

Contents?: true

Size: 1.22 KB

Versions: 21

Compression:

Stored size: 1.22 KB

Contents

module Bhf::ActionView
  module FormOptions

    def option_groups_from_collection_for_select_with_html_attrs(collection, group_method, group_label_method, option_key_method, option_value_method, selected_key, html_attrs)
      collection.map do |group|
        option_tags = options_from_collection_for_select_with_html_attrs(
          group.send(group_method), option_key_method, option_value_method, selected_key, html_attrs)

        content_tag(:optgroup, option_tags, label: group.send(group_label_method))
      end.join.html_safe
    end

    def options_from_collection_for_select_with_html_attrs(collection, value_method, text_method, selected, html_attrs)
      options = collection.map do |element|
        [
          value_for_collection(element, text_method), value_for_collection(element, value_method), option_html_attributes(element),
          html_attrs.call(element)
        ]
      end
      selected, disabled = extract_selected_and_disabled(selected)
      select_deselect = {
        selected: extract_values_from_collection(collection, value_method, selected),
        disabled: extract_values_from_collection(collection, value_method, disabled)
      }

      options_for_select(options, select_deselect)
    end

  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
bhf-1.0.0.beta16 lib/bhf/action_view/form_options.rb
bhf-1.0.0.beta15 lib/bhf/action_view/form_options.rb
bhf-1.0.0.beta14 lib/bhf/action_view/form_options.rb
bhf-1.0.0.beta13 lib/bhf/action_view/form_options.rb
bhf-1.0.0.beta12 lib/bhf/action_view/form_options.rb
bhf-1.0.0.beta11 lib/bhf/action_view/form_options.rb
bhf-1.0.0.beta10 lib/bhf/action_view/form_options.rb
bhf-1.0.0.beta9 lib/bhf/action_view/form_options.rb
bhf-1.0.0.beta8 lib/bhf/action_view/form_options.rb
bhf-1.0.0.beta7 lib/bhf/action_view/form_options.rb
bhf-1.0.0.beta6 lib/bhf/action_view/form_options.rb
bhf-1.0.0.beta5 lib/bhf/action_view/form_options.rb
bhf-1.0.0.beta4 lib/bhf/action_view/form_options.rb
bhf-1.0.0.beta3 lib/bhf/action_view/form_options.rb
bhf-1.0.0.beta2 lib/bhf/action_view/form_options.rb
bhf-1.0.0.beta1 lib/bhf/action_view/form_options.rb
bhf-0.10.17 lib/bhf/action_view/form_options.rb
bhf-0.10.16 lib/bhf/action_view/form_options.rb
bhf-0.10.15 lib/bhf/action_view/form_options.rb
bhf-0.10.14 lib/bhf/action_view/form_options.rb