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

Methods included from Base::Wrapping

#appended_input_wrapping, #bootstrap_wrapping, #control_group_wrapping, #controls_wrapper_html_options, #controls_wrapping, #prepended_and_appended_input_wrapping, #prepended_input_wrapping

Methods included from Base::Labelling

#control_label_html, #control_label_html_options, #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

#input_html_options

Instance Method Details

#choice_html(choice) ⇒ Object



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

def choice_html(choice)        
  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

#choice_wrapping_html_options(choice) ⇒ Object

This came from check_boxes. Do needed refactoring.



30
31
32
33
34
# File 'lib/formtastic-bootstrap/inputs/radio_input.rb', line 30

def choice_wrapping_html_options(choice)
  super(choice).tap do |options|
    options[:class] = ((options[:class].split) << "radio").join(" ")
  end
end

#to_htmlObject

TODO Make sure help blocks work correctly. TODO Support .inline



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

def to_html
  control_group_wrapping do
    control_label_html <<
    controls_wrapping do
      collection.map { |choice|
        choice_html(choice)
      }.join("\n").html_safe
    end
  end
end

#wrapper_html_optionsObject



21
22
23
24
25
26
27
# File 'lib/formtastic-bootstrap/inputs/radio_input.rb', line 21

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