lib/formtastic/helpers/input_helper.rb in formtastic-2.1.1 vs lib/formtastic/helpers/input_helper.rb in formtastic-2.2.0.rc
- old
+ new
@@ -87,12 +87,12 @@
# Available input styles:
#
# * `:boolean` (see {Inputs::BooleanInput})
# * `:check_boxes` (see {Inputs::CheckBoxesInput})
# * `:country` (see {Inputs::CountryInput})
- # * `:datetime` (see {Inputs::DatetimeInput})
- # * `:date` (see {Inputs::DateInput})
+ # * `:datetime_select` (see {Inputs::DatetimeSelectInput})
+ # * `:date_select` (see {Inputs::DateSelectInput})
# * `:email` (see {Inputs::EmailInput})
# * `:file` (see {Inputs::FileInput})
# * `:hidden` (see {Inputs::HiddenInput})
# * `:number` (see {Inputs::NumberInput})
# * `:password` (see {Inputs::PasswordInput})
@@ -101,11 +101,11 @@
# * `:search` (see {Inputs::SearchInput})
# * `:select` (see {Inputs::SelectInput})
# * `:string` (see {Inputs::StringInput})
# * `:text` (see {Inputs::TextInput})
# * `:time_zone` (see {Inputs::TimeZoneInput})
- # * `:time` (see {Inputs::TimeInput})
+ # * `:time_select` (see {Inputs::TimeSelectInput})
# * `:url` (see {Inputs::UrlInput})
#
# Calling `:as => :string` (for example) will call `#to_html` on a new instance of
# `Formtastic::Inputs::StringInput`. Before this, Formtastic will try to instantiate a top-level
# namespace StringInput, meaning you can subclass and modify `Formtastic::Inputs::StringInput`
@@ -141,38 +141,20 @@
# 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 :hint_class [String]
- # Override the `class` attribute applied to the `<p>` tag used when a `:hint` is rendered for an input
- #
- # @option options :error_class [String]
- # Override the `class` attribute applied to the `<p>` or `<ol>` tag used when inline errors are rendered for an input
- #
# @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)
#
- # @option options :group_by [Symbol]
- # TODO will probably be deprecated
- #
- # @option options :find_options [Symbol]
- # TODO will probably be deprecated
- #
- # @option options :group_label [Symbol]
- # TODO will probably be deprecated
- #
# @option options :include_blank [Boolean]
# Specify if a `:select` input should include a blank option or not (defaults to `include_blank_for_select_by_default` configuration)
#
# @option options :prompt [String]
# Specify the text in the first ('blank') `:select` input `<option>` to prompt a user to make a selection (implicitly sets `:include_blank` to `true`)
#
- # @todo Can we kill `:hint_class` & `:error_class`? What's the use case for input-by-input? Shift to config or burn!
- # @todo Can we kill `:group_by` & `:group_label`? Should be done with :collection => grouped_options_for_select(...)
- # @todo Can we kill `:find_options`? Should be done with MyModel.some_scope.where(...).order(...).whatever_scope
- # @todo Can we kill `:label`, `:hint` & `:prompt`? All strings could be shifted to i18n!
+ # @todo Can we deprecate & kill `:label`, `:hint` & `:prompt`? All strings could be shifted to i18n!
#
# @example Accept all default options
# <%= f.input :title %>
#
# @example Change the input type
@@ -291,12 +273,16 @@
when :integer
return :select if reflection_for(method)
return :number
when :float, :decimal
return :number
- when :timestamp
- return :datetime
+ when :datetime, :timestamp
+ return :datetime_select
+ when :time
+ return :time_select
+ when :date
+ return :date_select
end
# Try look for hints in options hash. Quite common senario: Enum keys stored as string in the database.
return :select if column.type == :string && options.key?(:collection)
# Try 3: Assume the input name will be the same as the column type (e.g. string_input).
@@ -345,11 +331,11 @@
if ::Object.const_defined?(input_class_name)
input_class_name.constantize
elsif Formtastic::Inputs.const_defined?(input_class_name)
standard_input_class_name(as).constantize
else
- raise Formtastic::UnknownInputError
+ raise Formtastic::UnknownInputError, "Unable to find input class #{input_class_name}"
end
end
# use auto-loading in development environment
def input_class_by_trying(as)
@@ -357,10 +343,10 @@
custom_input_class_name(as).constantize
rescue NameError
standard_input_class_name(as).constantize
end
rescue NameError
- raise Formtastic::UnknownInputError
+ raise Formtastic::UnknownInputError, "Unable to find input class for #{as}"
end
# :as => :string # => StringInput
def custom_input_class_name(as)
"#{as.to_s.camelize}Input"