module Formtastic module Inputs # A radio input is used to render a series of radio inputs. This is an alternative input choice # for `belongs_to` associations like a `Post` belonging to a `Section` or an `Author`, or any # case where the user needs to make a single selection from a pre-defined collectioon of choices. # # Within the standard `
  • ` wrapper, the output is a `
    ` with a `` to # represent the "label" for the input, and an `
      ` containing `
    1. `s for each choice in # the association. Each `
    2. ` choice has a `
    3. ` wrapper with `:wrapper_html` # <%= f.input :author, :as => :radio, :wrapper_html => { :class => "special" } %> # # @example `:value_as_class` can be used to add a class to the `
    4. ` wrapped around each choice using the radio value for custom styling of each choice # <%= f.input :author, :as => :radio, :value_as_class => true %> # # @example Set HTML options on a specific radio input option with a 3rd element in the array for a collection member # <%= f.input :author, :as => :radio, :collection => [["Test", 'test'], ["Try", "try", {:disabled => true}]] # # @see Formtastic::Helpers::InputsHelper#input InputsHelper#input for full documentation of all possible options. # @see Formtastic::Inputs::RadioInput as an alternative for `belongs_to` associations # # @todo :disabled like CheckBoxes? class RadioInput include Base include Base::Collections include Base::Choices def to_html input_wrapping do choices_wrapping do legend_html << choices_group_wrapping do collection.map { |choice| choice_wrapping(choice_wrapping_html_options(choice)) do choice_html(choice) end }.join("\n").html_safe end end end end def choice_html(choice) template.content_tag(: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(:for => choice_input_dom_id(choice), :class => nil) ) end # Override to remove the for attribute since this isn't associated with any element, as it's # nested inside the legend. def label_html_options super.merge(:for => nil) end end end end