module SimpleForm::ActionViewExtensions::Builder
def collection_check_boxes(attribute, collection, value_method, text_method, options={}, html_options={})
item or an array of items.
* disabled => the value or values that should be disabled. Accepts a single
a single item or an array of items.
* checked => the value or values that should be checked initially. Accepts
Collection check box accepts some extra options:
== Options
end
f.collection_check_box :options, [[true, 'Yes'] ,[false, 'No']], :first, :last
form_for @user do |f|
== Examples
the collection for use as text/value in check boxes.
with a clickable label. Use value_method and text_method to convert items in
Creates a collection of check boxes for each item in the collection, associated
def collection_check_boxes(attribute, collection, value_method, text_method, options={}, html_options={}) collection.inject('') do |result, item| value = item.send value_method text = item.send text_method default_html_options = default_html_options_for_collection(item, value, options, html_options) default_html_options[:multiple] = true check_box = check_box(attribute, default_html_options, value, '') result << label("#{attribute}_#{value}", check_box << text.to_s, :class => "collection_check_boxes") end end
def collection_radio(attribute, collection, value_method, text_method, options={}, html_options={})
item or an array of items.
* disabled => the value or values that should be disabled. Accepts a single
* checked => the value that should be checked initially.
Collection radio accepts some extra options:
== Options
end
f.collection_radio :options, [[true, 'Yes'] ,[false, 'No']], :first, :last
form_for @user do |f|
== Examples
to convert these text/value. Based on collection_select.
text/value option in the collection, using value_method and text_method
helper will create a radio input associated with a label for each
Create a collection of radio inputs for the attribute. Basically this
def collection_radio(attribute, collection, value_method, text_method, options={}, html_options={}) collection.inject('') do |result, item| value = item.send value_method text = item.send text_method default_html_options = default_html_options_for_collection(item, value, options, html_options) radio = radio_button(attribute, value, default_html_options) result << label("#{attribute}_#{value}", radio << text.to_s, :class => "collection_radio") end end
def default_html_options_for_collection(item, value, options, html_options) #:nodoc:
:disabled.
Generate default options for collection helpers, such as :checked and
def default_html_options_for_collection(item, value, options, html_options) #:nodoc: returning(html_options.dup) do |default_html_options| [:checked, :disabled].each do |option| next unless options[option] accept = if options[option].is_a?(Proc) options[option].call(item) else Array(options[option]).include?(value) end default_html_options[option] = true if accept end end end
def simple_fields_for(*args, &block)
end
posts_form.input :title
# Here you have all simple_form methods available
f.simple_fields_for :posts do |posts_form|
form_for @user do |f|
Example:
Wrapper for using simple form inside a default rails form.
def simple_fields_for(*args, &block) options = args.extract_options! options[:builder] = SimpleForm::FormBuilder fields_for(*(args << options), &block) end