Method: SimpleForm::ActionViewExtensions::Builder#collection_check_boxes
- Defined in:
- lib/simple_form/action_view_extensions/builder.rb
#collection_check_boxes(attribute, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
Creates a collection of check boxes for each item in the collection, associated with a clickable label. Use value_method and text_method to convert items in the collection for use as text/value in check boxes. You can give a symbol or a proc to both value_method and text_method, that will be evaluated for each item in the collection.
Examples
form_for @user do |f|
f.collection_check_boxes :options, [[true, 'Yes'] ,[false, 'No']], :first, :last
end
<input name="user[options][]" type="hidden" value="" />
<input id="user_options_true" name="user[options][]" type="checkbox" value="true" />
<label class="collection_check_boxes" for="user_options_true">Yes</label>
<input name="user[options][]" type="hidden" value="" />
<input id="user_options_false" name="user[options][]" type="checkbox" value="false" />
<label class="collection_check_boxes" for="user_options_false">No</label>
Options
Collection check box accepts some extra options:
* checked => the value or values that should be checked initially. Accepts
a single item or an array of items.
* disabled => the value or values that should be disabled. Accepts a single
item or an array of items.
* collection_wrapper_tag => the tag to wrap the entire collection.
* item_wrapper_tag => the tag to wrap each item in the collection.
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/simple_form/action_view_extensions/builder.rb', line 80 def collection_check_boxes(attribute, collection, value_method, text_method, ={}, ={}) render_collection( attribute, collection, value_method, text_method, , ) do |value, text, | [:multiple] = true check_box = check_box(attribute, , value, '') collection_label(attribute, value, check_box, text, :class => "collection_check_boxes") end end |