Module: ActionView::Helpers::FormOptionsHelper
- Defined in:
- lib/plugins/option_tags_with_disable/lib/option_tags_will_disable.rb
Instance Method Summary collapse
- #collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
- #option_groups_from_collection_for_select(collection, group_method, group_label_method, option_key_method, option_value_method, selected_key = nil, disabled = nil) ⇒ Object
- #options_for_select(container, selected = nil, disabled = nil) ⇒ Object
- #options_from_collection_for_select(collection, value_method, text_method, selected = nil, disabled = nil) ⇒ Object
- #select(object, method, choices, options = {}, html_options = {}) ⇒ Object
Instance Method Details
#collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
11 12 13 |
# File 'lib/plugins/option_tags_with_disable/lib/option_tags_will_disable.rb', line 11 def collection_select(object, method, collection, value_method, text_method, = {}, = {}) InstanceTag.new(object, method, self, .delete(:object)).to_collection_select_tag(collection, value_method, text_method, , ) end |
#option_groups_from_collection_for_select(collection, group_method, group_label_method, option_key_method, option_value_method, selected_key = nil, disabled = nil) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/plugins/option_tags_with_disable/lib/option_tags_will_disable.rb', line 52 def option_groups_from_collection_for_select(collection, group_method, group_label_method, option_key_method, option_value_method, selected_key = nil, disabled = nil) collection.inject("") do |, group| group_label_string = eval("group.#{group_label_method}") += "<optgroup label=\"#{html_escape(group_label_string)}\">" += (eval("group.#{group_method}"), option_key_method, option_value_method, selected_key, disabled) += '</optgroup>' end end |
#options_for_select(container, selected = nil, disabled = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/plugins/option_tags_with_disable/lib/option_tags_will_disable.rb', line 15 def (container, selected = nil, disabled = nil) container = container.to_a if Hash === container = container.inject([]) do |, element| text, value = option_text_and_value(element) selected_attribute = ' selected="selected"' if option_value_selected?(value, selected) disabled_attribute = ' disabled="disabled"' if option_value_selected?(value, disabled) && disabled != nil << %(<option value="#{html_escape(value.to_s)}"#{selected_attribute}#{disabled_attribute}>#{html_escape(text.to_s)}</option>) end .join("\n") end |
#options_from_collection_for_select(collection, value_method, text_method, selected = nil, disabled = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/plugins/option_tags_with_disable/lib/option_tags_will_disable.rb', line 28 def (collection, value_method, text_method, selected = nil, disabled = nil) = collection.map do |element| [element.send(text_method), element.send(value_method)] end if selected.is_a?(Proc) selected_values = collection.map do |element| element.send(value_method) if selected.call(element) end.compact else selected_values = selected end if disabled.is_a?(Proc) disabled_values = collection.map do |element| element.send(value_method) if disabled.call(element) end.compact else disabled_values = disabled end (, selected_values, disabled_values) end |
#select(object, method, choices, options = {}, html_options = {}) ⇒ Object
7 8 9 |
# File 'lib/plugins/option_tags_with_disable/lib/option_tags_will_disable.rb', line 7 def select(object, method, choices, = {}, = {}) InstanceTag.new(object, method, self, .delete(:object)).to_select_tag(choices, , ) end |