Deprecate :radio input type and collection_radio helper, update changelog
This commit is contained in:
parent
b21e3c57e6
commit
634c4430b9
|
@ -30,10 +30,14 @@
|
|||
* Do not generate hidden check box field when using nested boolean style, as it is considered
|
||||
invalid markup in HTML5. This will only work in Rails > 3.2.1 (not released at this time).
|
||||
More info in [#215](https://github.com/plataformatec/simple_form/issues/215)
|
||||
* Add `item_wrapper_class` configuration option for collection radio buttons / check boxes inputs.
|
||||
|
||||
### deprecation
|
||||
* Deprecate the `translate` configuration in favor of `translate_labels`
|
||||
* Deprecate the `html5` configuration in favor of a new `html5` component
|
||||
* Deprecate `:radio` input type in favor of `:radio_buttons`
|
||||
* Deprecate `collection_radio` form helper in favor of `collection_radio_buttons`
|
||||
(the label class has changed as well)
|
||||
|
||||
### bug fix
|
||||
* Fix i18n lookup with attributes with same name of models.
|
||||
|
|
|
@ -178,19 +178,23 @@ module SimpleForm
|
|||
|
||||
DEPRECATED.each do |method|
|
||||
class_eval "def self.#{method}=(*); @@deprecated << :#{method}=; end"
|
||||
class_eval "def self.#{method}; ActiveSupport::Deprecation.warn 'SimpleForm.#{method} is deprecated and has no effect'; end"
|
||||
class_eval "def self.#{method}; deprecation_warn 'SimpleForm.#{method} is deprecated and has no effect'; end"
|
||||
end
|
||||
|
||||
def self.translate=(value)
|
||||
ActiveSupport::Deprecation.warn "SimpleForm.translate= is disabled in favor of translate_labels="
|
||||
deprecation_warn "SimpleForm.translate= is disabled in favor of translate_labels="
|
||||
self.translate_labels = value
|
||||
end
|
||||
|
||||
def self.translate
|
||||
ActiveSupport::Deprecation.warn "SimpleForm.translate is disabled in favor of translate_labels"
|
||||
deprecation_warn "SimpleForm.translate is disabled in favor of translate_labels"
|
||||
self.translate_labels
|
||||
end
|
||||
|
||||
def self.deprecation_warn(message)
|
||||
ActiveSupport::Deprecation.warn "[SIMPLE_FORM] #{message}", caller
|
||||
end
|
||||
|
||||
# Default way to setup SimpleForm. Run rails generate simple_form:install
|
||||
# to create a fresh initializer with all configuration values.
|
||||
def self.setup
|
||||
|
|
|
@ -48,6 +48,8 @@ module SimpleForm
|
|||
#
|
||||
# * item_wrapper_tag => the tag to wrap each item in the collection.
|
||||
#
|
||||
# * item_wrapper_class => the CSS class to use for item_wrapper_tag
|
||||
#
|
||||
# * a block => to generate the label + radio or any other component.
|
||||
#
|
||||
def collection_radio_buttons(attribute, collection, value_method, text_method, options={}, html_options={})
|
||||
|
@ -63,6 +65,13 @@ module SimpleForm
|
|||
end
|
||||
end
|
||||
|
||||
# deprecated
|
||||
def collection_radio(*args, &block)
|
||||
SimpleForm.deprecation_warn "The `collection_radio` helper is deprecated, " \
|
||||
"please use `collection_radio_buttons` instead."
|
||||
collection_radio_buttons(*args, &block)
|
||||
end
|
||||
|
||||
# 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.
|
||||
|
@ -109,6 +118,8 @@ module SimpleForm
|
|||
#
|
||||
# * item_wrapper_tag => the tag to wrap each item in the collection.
|
||||
#
|
||||
# * item_wrapper_class => the CSS class to use for item_wrapper_tag
|
||||
#
|
||||
# * a block => to generate the label + check box or any other component.
|
||||
#
|
||||
def collection_check_boxes(attribute, collection, value_method, text_method, options={}, html_options={})
|
||||
|
|
|
@ -347,6 +347,12 @@ module SimpleForm
|
|||
column = find_attribute_column(attribute_name)
|
||||
input_type = default_input_type(attribute_name, column, options)
|
||||
|
||||
if input_type == :radio
|
||||
SimpleForm.deprecation_warn "Using `:as => :radio` as input type is " \
|
||||
"deprecated, please change it to `:as => :radio_buttons`."
|
||||
input_type = :radio_buttons
|
||||
end
|
||||
|
||||
if block_given?
|
||||
SimpleForm::Inputs::BlockInput.new(self, attribute_name, column, input_type, options, &block)
|
||||
else
|
||||
|
|
|
@ -183,6 +183,18 @@ class BuilderTest < ActionView::TestCase
|
|||
assert_select 'form label[for=user_active_false] > input#user_active_false[type=radio]'
|
||||
end
|
||||
|
||||
test 'collection_radio helper is deprecated in favor of collection_radio_buttons' do
|
||||
assert_deprecated "[SIMPLE_FORM] The `collection_radio` helper is deprecated, " \
|
||||
"please use `collection_radio_buttons` instead" do
|
||||
with_concat_form_for(@user) do |f|
|
||||
f.collection_radio :active, [true, false], :to_s, :to_s
|
||||
end
|
||||
end
|
||||
|
||||
assert_select 'input[type=radio][value=true]'
|
||||
assert_select 'input[type=radio][value=false]'
|
||||
end
|
||||
|
||||
# COLLECTION CHECK BOX
|
||||
test 'collection check box accepts a collection and generate a serie of checkboxes for value method' do
|
||||
collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')]
|
||||
|
|
|
@ -6,6 +6,15 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|||
SimpleForm::Inputs::CollectionRadioButtonsInput.reset_i18n_cache :boolean_collection
|
||||
end
|
||||
|
||||
test 'input :as => :radio is deprecated in favor of :as => :radio_buttons' do
|
||||
assert_deprecated "[SIMPLE_FORM] Using `:as => :radio` as " \
|
||||
"input type is deprecated, please change it to `:as => :radio_buttons`." do
|
||||
with_input_for @user, :active, :radio
|
||||
end
|
||||
|
||||
assert_select 'input[type=radio].radio_buttons', :count => 2
|
||||
end
|
||||
|
||||
test 'input should generate boolean radio buttons by default for radio types' do
|
||||
with_input_for @user, :active, :radio_buttons
|
||||
assert_select 'input[type=radio][value=true].radio_buttons#user_active_true'
|
||||
|
|
Loading…
Reference in New Issue