module Formtastic::Inputs::Base::Choices
Public Instance Methods
choice_html(choice)
click to toggle source
# File lib/formtastic/inputs/base/choices.rb, line 42 def choice_html(choice) raise "choice_html() needs to be implemented when including Formtastic::Inputs::Base::Choices" end
choice_html_options(choice)
click to toggle source
# File lib/formtastic/inputs/base/choices.rb, line 58 def choice_html_options(choice) custom_choice_html_options(choice).merge(default_choice_html_options(choice)) end
choice_html_safe_value(choice)
click to toggle source
# File lib/formtastic/inputs/base/choices.rb, line 70 def choice_html_safe_value(choice) choice_value(choice).to_s.gsub(/\s/, '_').gsub(/[^\w-]/, '').downcase end
choice_input_dom_id(choice)
click to toggle source
# File lib/formtastic/inputs/base/choices.rb, line 74 def choice_input_dom_id(choice) [ builder.dom_id_namespace, sanitized_object_name, builder.options[:index], association_primary_key || method, choice_html_safe_value(choice) ].compact.reject { |i| i.blank? }.join("_") end
choice_label(choice)
click to toggle source
# File lib/formtastic/inputs/base/choices.rb, line 46 def choice_label(choice) if choice.is_a?(Array) choice.first else choice end.to_s end
choice_value(choice)
click to toggle source
# File lib/formtastic/inputs/base/choices.rb, line 54 def choice_value(choice) choice.is_a?(Array) ? choice[1] : choice end
choice_wrapping(html_options, &block)
click to toggle source
# File lib/formtastic/inputs/base/choices.rb, line 28 def choice_wrapping(html_options, &block) template.content_tag(:li, template.capture(&block), html_options ) end
choice_wrapping_html_options(choice)
click to toggle source
# File lib/formtastic/inputs/base/choices.rb, line 35 def choice_wrapping_html_options(choice) classes = ['choice'] classes << "#{sanitized_method_name.singularize}_#{choice_html_safe_value(choice)}" if value_as_class? { :class => classes.join(" ") } end
choices_group_wrapping(&block)
click to toggle source
# File lib/formtastic/inputs/base/choices.rb, line 17 def choices_group_wrapping(&block) template.content_tag(:ol, template.capture(&block), choices_group_wrapping_html_options ) end
choices_group_wrapping_html_options()
click to toggle source
# File lib/formtastic/inputs/base/choices.rb, line 24 def choices_group_wrapping_html_options { :class => "choices-group" } end
choices_wrapping(&block)
click to toggle source
# File lib/formtastic/inputs/base/choices.rb, line 6 def choices_wrapping(&block) template.content_tag(:fieldset, template.capture(&block), choices_wrapping_html_options ) end
choices_wrapping_html_options()
click to toggle source
# File lib/formtastic/inputs/base/choices.rb, line 13 def choices_wrapping_html_options { :class => "choices" } end
custom_choice_html_options(choice)
click to toggle source
# File lib/formtastic/inputs/base/choices.rb, line 66 def custom_choice_html_options(choice) (choice.is_a?(Array) && choice.size > 2) ? choice.last : {} end
default_choice_html_options(choice)
click to toggle source
# File lib/formtastic/inputs/base/choices.rb, line 62 def default_choice_html_options(choice) { :id => choice_input_dom_id(choice) } end
label_html_options()
click to toggle source
Override to remove the for attribute since this isn't associated with any element, as it's nested inside the legend.
Calls superclass method
# File lib/formtastic/inputs/base/choices.rb, line 101 def label_html_options super.merge(:for => nil) end
legend_html()
click to toggle source
# File lib/formtastic/inputs/base/choices.rb, line 88 def legend_html if render_label? template.content_tag(:legend, template.content_tag(:label, label_text), label_html_options.merge(:class => "label") ) else "".html_safe end end
value_as_class?()
click to toggle source
# File lib/formtastic/inputs/base/choices.rb, line 84 def value_as_class? options[:value_as_class] end