Skip to content

Commit

Permalink
documentation for the recent changes to :label_method, which now acce…
Browse files Browse the repository at this point in the history
…pts a Method object for use with helper_methods
  • Loading branch information
justinfrench committed May 4, 2011
1 parent 38fae41 commit 116d645
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/formtastic/helpers/input_helper.rb
Expand Up @@ -136,10 +136,10 @@ module InputHelper
# @option options :collection [Array<ActiveModel, String, Symbol>, Hash{String => String, Boolean}, OrderedHash{String => String, Boolean}]
# Override collection of objects in the association (`:select`, `:radio` & `:check_boxes` inputs only)
#
# @option options :label_method [Symbol, Proc]
# @option options :label_method [Symbol, Proc, Method]
# Override the method called on each object in the `:collection` for use as the `<label>` content (`:check_boxes` & `:radio` inputs) or `<option>` content (`:select` inputs)
#
# @option options :value_method [Symbol, Proc]
# @option options :value_method [Symbol, Proc, Method]
# Override the method called on each object in the `:collection` for use as the `value` attribute in the `<input>` (`:check_boxes` & `:radio` inputs) or `<option>` (`:select` inputs)
#
# @option options :hint_class [String]
Expand Down
10 changes: 9 additions & 1 deletion lib/formtastic/inputs/check_boxes_input.rb
Expand Up @@ -55,13 +55,21 @@ module Inputs
# @example `:label_method` can be used to call a different method (or a Proc) on each object in the collection for rendering the label text (it'll try the methods like `to_s` in `collection_label_methods` config by default)
# <%= f.input :categories, :as => :check_boxes, :label_method => :name %>
# <%= f.input :categories, :as => :check_boxes, :label_method => :name_with_post_count
# <%= f.input :categories, :as => :check_boxes, :label_method => Proc.new { |c| "#{c.name} (#{pluralize("post", c.posts.count)})" }
# <%= f.input :categories, :as => :check_boxes, :label_method => { |c| "#{c.name} (#{pluralize("post", c.posts.count)})" }
#
# @example `:label_method` can be used with a helper method (both examples have the same result)
# <%= f.input :categories, :as => :check_boxes, :label_method => method(:fancy_label)
# <%= f.input :categories, :as => :check_boxes, :label_method => Proc.new { |category| fancy_label(category) }
#
# @example `:value_method` can be used to call a different method (or a Proc) on each object in the collection for rendering the value for each checkbox (it'll try the methods like `id` in `collection_value_methods` config by default)
# <%= f.input :categories, :as => :check_boxes, :value_method => :code %>
# <%= f.input :categories, :as => :check_boxes, :value_method => :isbn
# <%= f.input :categories, :as => :check_boxes, :value_method => Proc.new { |c| c.name.downcase.underscore }
#
# @example `:value_method` can be used with a helper method (both examples have the same result)
# <%= f.input :categories, :as => :check_boxes, :value_method => method(:some_helper)
# <%= f.input :categories, :as => :check_boxes, :value_method => Proc.new { |category| some_helper(category) }
#
# @example `:value_as_class` can be used to add a class to the `<li>` wrapped around each choice using the checkbox value for custom styling of each choice
# <%= f.input :categories, :as => :check_boxes, :value_as_class => true %>
#
Expand Down
8 changes: 8 additions & 0 deletions lib/formtastic/inputs/radio_input.rb
Expand Up @@ -90,10 +90,18 @@ module Inputs
# <%= f.input :author, :as => :radio, :label_method => :name_with_post_count
# <%= f.input :author, :as => :radio, :label_method => Proc.new { |a| "#{c.name} (#{pluralize("post", a.posts.count)})" }
#
# @example `:label_method` can be used with a helper method (both examples have the same result)
# <%= f.input :author, :as => :radio, :label_method => method(:fancy_label)
# <%= f.input :author, :as => :radio, :label_method => Proc.new { |author| fancy_label(author) }
#
# @example The `:value_method` can be used to call a different method (or a Proc) on each object in the collection for rendering the value for each checkbox (it'll try the methods like `id` in `collection_value_methods` config by default)
# <%= f.input :author, :as => :radio, :value_method => :login %>
# <%= f.input :author, :as => :radio, :value_method => Proc.new { |c| c.full_name.downcase.underscore }
#
# @example `:value_method` can be used with a helper method (both examples have the same result)
# <%= f.input :author, :as => :radio, :value_method => method(:some_helper)
# <%= f.input :author, :as => :radio, :value_method => Proc.new { |author| some_helper(author) }
#
# @example Set HTML attributes on each `<input type="radio">` tag with `:input_html`
# <%= f.input :author, :as => :radio, :input_html => { :size => 20, :multiple => true, :class => "special" } %>
#
Expand Down

0 comments on commit 116d645

Please sign in to comment.