Class: FormtasticBootstrap::Inputs::RadioInput

Inherits:
Formtastic::Inputs::RadioInput
  • Object
show all
Includes:
Base, Base::Choices
Defined in:
lib/formtastic-bootstrap/inputs/radio_input.rb

Instance Method Summary collapse

Methods included from Base::Choices

#choice_label_html_options, #choice_wrapping_html_options

Methods included from Base::Wrapping

#add_on_content, #add_on_wrapper_classes, #bootstrap_wrapping, #form_group_wrapping, #input_content, #prepended_or_appended?

Methods included from Base::Labelling

#label_html, #label_html_options

Methods included from Base::Hints

#hint_html

Methods included from Base::Errors

#error_first_html, #error_html, #error_list_html, #error_none_html, #error_sentence_html

Methods included from Base::Html

#form_control_input_html_options, #input_html_options

Instance Method Details

#choice_html(choice) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/formtastic-bootstrap/inputs/radio_input.rb', line 25

def choice_html(choice)
  radio_wrapping do
    template.(:label,
      builder.radio_button(input_name, choice_value(choice), input_html_options.merge(choice_html_options(choice)).merge(:required => false)) <<
      choice_label(choice),
      label_html_options.merge(choice_label_html_options(choice))
    )
  end
end

#radio_wrapping(&block) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/formtastic-bootstrap/inputs/radio_input.rb', line 35

def radio_wrapping(&block)
  class_name = "radio"
  class_name += " radio-inline" if options[:inline]
  template.(:div,
    template.capture(&block).html_safe,
    :class => class_name
  )
end

#to_htmlObject

TODO Make sure help blocks work correctly.



9
10
11
12
13
14
15
# File 'lib/formtastic-bootstrap/inputs/radio_input.rb', line 9

def to_html
  bootstrap_wrapping do
    collection.map { |choice|
      choice_html(choice)
    }.join("\n").html_safe
  end
end

#wrapper_html_optionsObject



17
18
19
20
21
22
23
# File 'lib/formtastic-bootstrap/inputs/radio_input.rb', line 17

def wrapper_html_options
  # Formtastic marks these as 'radio' but Bootstrap does something
  # with that, so change it to 'radio_buttons'.
  super.tap do |options|
    options[:class] = options[:class].gsub("radio", "radio_buttons")
  end
end