Module: Formtastic::Inputs::Base::Choices
- Included in:
- CheckBoxesInput, RadioInput
- Defined in:
- lib/formtastic/inputs/base/choices.rb
Instance Method Summary (collapse)
- - (Object) choice_html(choice)
- - (Object) choice_html_options(choice)
- - (Object) choice_html_safe_value(choice)
- - (Object) choice_input_dom_id(choice)
- - (Object) choice_label(choice)
- - (Object) choice_value(choice)
- - (Object) choice_wrapping(html_options, &block)
- - (Object) choice_wrapping_html_options(choice)
- - (Object) choices_group_wrapping(&block)
- - (Object) choices_group_wrapping_html_options
- - (Object) choices_wrapping(&block)
- - (Object) choices_wrapping_html_options
- - (Object) custom_choice_html_options(choice)
- - (Object) default_choice_html_options(choice)
-
- (Object) label_html_options
Override to remove the for attribute since this isn't associated with any element, as it's nested inside the legend.
- - (Object) legend_html
- - (Boolean) value_as_class?
Instance Method Details
- (Object) choice_html(choice)
42 43 44 |
# 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 |
- (Object) choice_html_options(choice)
58 59 60 |
# File 'lib/formtastic/inputs/base/choices.rb', line 58 def (choice) (choice).merge((choice)) end |
- (Object) choice_html_safe_value(choice)
70 71 72 |
# 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 |
- (Object) choice_input_dom_id(choice)
74 75 76 77 78 79 80 81 82 |
# File 'lib/formtastic/inputs/base/choices.rb', line 74 def choice_input_dom_id(choice) [ builder.custom_namespace, sanitized_object_name, builder.[:index], association_primary_key || method, choice_html_safe_value(choice) ].compact.reject { |i| i.blank? }.join("_") end |
- (Object) choice_label(choice)
46 47 48 49 50 51 52 |
# 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 |
- (Object) choice_value(choice)
54 55 56 |
# File 'lib/formtastic/inputs/base/choices.rb', line 54 def choice_value(choice) choice.is_a?(Array) ? choice[1] : choice end |
- (Object) choice_wrapping(html_options, &block)
28 29 30 31 32 33 |
# File 'lib/formtastic/inputs/base/choices.rb', line 28 def choice_wrapping(, &block) template.content_tag(:li, template.capture(&block), ) end |
- (Object) choice_wrapping_html_options(choice)
35 36 37 38 39 40 |
# File 'lib/formtastic/inputs/base/choices.rb', line 35 def (choice) classes = ['choice'] classes << "#{sanitized_method_name.singularize}_#{choice_html_safe_value(choice)}" if value_as_class? { :class => classes.join(" ") } end |
- (Object) choices_group_wrapping(&block)
17 18 19 20 21 22 |
# File 'lib/formtastic/inputs/base/choices.rb', line 17 def choices_group_wrapping(&block) template.content_tag(:ol, template.capture(&block), ) end |
- (Object) choices_group_wrapping_html_options
24 25 26 |
# File 'lib/formtastic/inputs/base/choices.rb', line 24 def { :class => "choices-group" } end |
- (Object) choices_wrapping(&block)
6 7 8 9 10 11 |
# File 'lib/formtastic/inputs/base/choices.rb', line 6 def choices_wrapping(&block) template.content_tag(:fieldset, template.capture(&block), ) end |
- (Object) choices_wrapping_html_options
13 14 15 |
# File 'lib/formtastic/inputs/base/choices.rb', line 13 def { :class => "choices" } end |
- (Object) custom_choice_html_options(choice)
66 67 68 |
# File 'lib/formtastic/inputs/base/choices.rb', line 66 def (choice) (choice.is_a?(Array) && choice.size > 2) ? choice.last : {} end |
- (Object) default_choice_html_options(choice)
62 63 64 |
# File 'lib/formtastic/inputs/base/choices.rb', line 62 def (choice) { :id => choice_input_dom_id(choice) } end |
- (Object) label_html_options
Override to remove the for attribute since this isn't associated with any element, as it's nested inside the legend.
101 102 103 |
# File 'lib/formtastic/inputs/base/choices.rb', line 101 def super.merge(:for => nil) end |
- (Object) legend_html
88 89 90 91 92 93 94 95 96 97 |
# 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), .merge(:class => "label") ) else "".html_safe end end |
- (Boolean) value_as_class?
84 85 86 |
# File 'lib/formtastic/inputs/base/choices.rb', line 84 def value_as_class? [:value_as_class] end |