Skip to content

Commit

Permalink
deprecate :member_label and :member_value
Browse files Browse the repository at this point in the history
  • Loading branch information
justinfrench committed Nov 5, 2014
1 parent 85637dd commit 9f96954
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 55 deletions.
2 changes: 1 addition & 1 deletion README.textile
Expand Up @@ -191,7 +191,7 @@ If you want to customize the label text, or render some hint text below the fiel
<%= f.inputs :name => "Advanced Options", :id => "advanced" do %>
<%= f.input :slug, :label => "URL Title", :hint => "Created automatically if left blank", :required => false %>
<%= f.input :section, :as => :radio %>
<%= f.input :user, :label => "Author", :member_label => :full_name %>
<%= f.input :user, :label => "Author" %>
<%= f.input :categories, :required => false %>
<%= f.input :created_at, :as => :string, :label => "Publication Date", :required => false %>
<% end %>
Expand Down
6 changes: 0 additions & 6 deletions lib/formtastic/helpers/input_helper.rb
Expand Up @@ -141,12 +141,6 @@ 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 :member_label [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 :member_value [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 :multiple [Boolean]
# Specify if the `:select` input should allow multiple selections or not (defaults to `belongs_to` associations, and `true` for `has_many` and `has_and_belongs_to_many` associations)
#
Expand Down
5 changes: 5 additions & 0 deletions lib/formtastic/inputs/base.rb
Expand Up @@ -11,6 +11,11 @@ def initialize(builder, template, object, object_name, method, options)
@object_name = object_name
@method = method
@options = options.dup

# Deprecate :member_label and :member_value, remove v4.0
member_deprecation_message = "passing an Array of label/value pairs like [['Justin', 2], ['Kate', 3]] into :collection directly (consider building the array in your model using Model.pluck)"
warn_deprecated_option!(:member_label, member_deprecation_message)
warn_deprecated_option!(:member_value, member_deprecation_message)
end

# Usefull for deprecating options.
Expand Down
18 changes: 0 additions & 18 deletions lib/formtastic/inputs/check_boxes_input.rb
Expand Up @@ -57,24 +57,6 @@ module Inputs
# @example `:disabled` can be used to disable any checkboxes with a value found in the given Array
# <%= f.input :categories, :as => :check_boxes, :collection => ["a", "b"], :disabled => ["a"] %>
#
# @example `:member_label` 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, :member_label => :name %>
# <%= f.input :categories, :as => :check_boxes, :member_label => :name_with_post_count
# <%= f.input :categories, :as => :check_boxes, :member_label => { |c| "#{c.name} (#{pluralize("post", c.posts.count)})" }
#
# @example `:member_label` can be used with a helper method (both examples have the same result)
# <%= f.input :categories, :as => :check_boxes, :member_label => method(:fancy_label)
# <%= f.input :categories, :as => :check_boxes, :member_label => Proc.new { |category| fancy_label(category) }
#
# @example `:member_value` 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, :member_value => :code %>
# <%= f.input :categories, :as => :check_boxes, :member_value => :isbn
# <%= f.input :categories, :as => :check_boxes, :member_value => Proc.new { |c| c.name.downcase.underscore }
#
# @example `:member_value` can be used with a helper method (both examples have the same result)
# <%= f.input :categories, :as => :check_boxes, :member_value => method(:some_helper)
# <%= f.input :categories, :as => :check_boxes, :member_value => 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
24 changes: 3 additions & 21 deletions lib/formtastic/inputs/radio_input.rb
Expand Up @@ -31,10 +31,9 @@ module Inputs
# `Section.all` for a `Post` form with an input for a `belongs_to :section` association.
# You can override or customise this collection through the `:collection` option (see examples).
#
# The way on which Formtastic renders the `value` attribute and label for each choice is
# customisable through the `:member_label` and `:member_value` options (see examples below).
# When not provided, we fall back to a list of methods to try on each object such as
# `:to_label`, `:name` and `:to_s`, which are defined in the configurations
# The way on which Formtastic renders the `value` attribute and label for each choice in the `:collection` is
# customisable (see examples below). When not provided, we fall back to a list of methods to try on each
# object such as `:to_label`, `:name` and `:to_s`, which are defined in the configurations
# `collection_label_methods` and `collection_value_methods`.
#
# @example Basic `belongs_to` example with full form context
Expand Down Expand Up @@ -89,23 +88,6 @@ module Inputs
# <%= f.input :author, :as => :radio, :collection => [:justin, :kate] %>
# <%= f.input :author, :as => :radio, :collection => 1..5 %>
#
# @example The `:member_label` 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 :author, :as => :radio, :member_label => :name %>
# <%= f.input :author, :as => :radio, :member_label => :name_with_post_count
# <%= f.input :author, :as => :radio, :member_label => Proc.new { |a| "#{c.name} (#{pluralize("post", a.posts.count)})" }
#
# @example `:member_label` can be used with a helper method (both examples have the same result)
# <%= f.input :author, :as => :radio, :member_label => method(:fancy_label)
# <%= f.input :author, :as => :radio, :member_label => Proc.new { |author| fancy_label(author) }
#
# @example The `:member_value` 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, :member_value => :login %>
# <%= f.input :author, :as => :radio, :member_value => Proc.new { |c| c.full_name.downcase.underscore }
#
# @example `:member_value` can be used with a helper method (both examples have the same result)
# <%= f.input :author, :as => :radio, :member_value => method(:some_helper)
# <%= f.input :author, :as => :radio, :member_value => 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
9 changes: 0 additions & 9 deletions lib/formtastic/inputs/select_input.rb
Expand Up @@ -108,15 +108,6 @@ module Inputs
# <%= f.input :author, :as => :select, :collection => grouped_options_for_select(...) %>
# <%= f.input :author, :as => :select, :collection => time_zone_options_for_select(...) %>
#
# @example The `:member_label` 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 :author, :as => :select, :member_label => :name %>
# <%= f.input :author, :as => :select, :member_label => :name_with_post_count %>
# <%= f.input :author, :as => :select, :member_label => Proc.new { |a| "#{c.name} (#{pluralize("post", a.posts.count)})" } %>
#
# @example The `:member_value` 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 => :select, :member_value => :login %>
# <%= f.input :author, :as => :select, :member_value => Proc.new { |c| c.full_name.downcase.underscore } %>
#
# @example Set HTML attributes on the `<select>` tag with `:input_html`
# <%= f.input :authors, :as => :select, :input_html => { :size => 20, :multiple => true, :class => "special" } %>
#
Expand Down

0 comments on commit 9f96954

Please sign in to comment.