From d796f6a8d2d63d3b3b3009d521eca00a9ddf07dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?George=20Guimar=C3=A3es?= Date: Tue, 30 Aug 2011 21:31:48 -0300 Subject: [PATCH] Fix bug that disable the entire select and wrapper when option is a string or array. Closes #301 --- CHANGELOG.rdoc | 1 + lib/simple_form/inputs/base.rb | 2 +- test/inputs_test.rb | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 55d43d50..a34793ac 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -11,6 +11,7 @@ * bug fix * Fix bug when simple_fields_for is used with a hash like models and Rails 3.1 * Fix bug that doesn't remove the item_wrapper_tag or the collection_wrapper_tag on collection inputs when nil or false value is passed to these options (by gitbub.com/dw2) + * Fix bug that disable the entire select and wrapper when `disabled` option is a string or array == 1.4.2 diff --git a/lib/simple_form/inputs/base.rb b/lib/simple_form/inputs/base.rb index 41e44da3..c28a1565 100644 --- a/lib/simple_form/inputs/base.rb +++ b/lib/simple_form/inputs/base.rb @@ -125,7 +125,7 @@ module SimpleForm end def disabled? - options[:disabled] + options[:disabled] === true end # Lookup translations for the given namespace using I18n, based on object name, diff --git a/test/inputs_test.rb b/test/inputs_test.rb index 188139d7..21700ce9 100644 --- a/test/inputs_test.rb +++ b/test/inputs_test.rb @@ -720,6 +720,22 @@ class InputTest < ActionView::TestCase assert_select 'select option[value=2]', 'Carlos' end + test 'input should disable the anothers components when the option is a object' do + with_input_for @user, :description, :select, :collection => ["Jose", "Carlos"], :disabled => true + assert_no_select 'select option[value=Jose][disabled=disabled]', 'Jose' + assert_no_select 'select option[value=Carlos][disabled=disabled]', 'Carlos' + assert_select 'select[disabled=disabled]' + assert_select 'div.disabled' + end + + test 'input should not disable the anothers components when the option is a object' do + with_input_for @user, :description, :select, :collection => ["Jose", "Carlos"], :disabled => 'Jose' + assert_select 'select option[value=Jose][disabled=disabled]', 'Jose' + assert_no_select 'select option[value=Carlos][disabled=disabled]', 'Carlos' + assert_no_select 'select[disabled=disabled]' + assert_no_select 'div.disabled' + end + test 'input should allow overriding collection for radio types' do with_input_for @user, :name, :radio, :collection => ['Jose', 'Carlos'] assert_select 'input[type=radio][value=Jose]'