diff options
author | Guillermo Iguaran <guilleiguaran@gmail.com> | 2014-03-31 14:56:35 -0500 |
---|---|---|
committer | Guillermo Iguaran <guilleiguaran@gmail.com> | 2014-03-31 14:56:35 -0500 |
commit | 165d93b22ff5f8798296bd5d7642d0ddb8996c74 (patch) | |
tree | 8eaa04ec175538861532e2a715113d8ee09b1f2e | |
parent | 08c8ce6a88fc3c2c837f3de0bb8fcc1114593518 (diff) | |
parent | 95692c6179f987db84bb358de9091cc51a2736e0 (diff) | |
download | rails-165d93b22ff5f8798296bd5d7642d0ddb8996c74.tar.gz rails-165d93b22ff5f8798296bd5d7642d0ddb8996c74.tar.bz2 rails-165d93b22ff5f8798296bd5d7642d0ddb8996c74.zip |
Merge pull request #14539 from lparedes/master
Do not overwrite selected and disabled attributes
-rw-r--r-- | actionview/lib/action_view/helpers/form_options_helper.rb | 4 | ||||
-rw-r--r-- | actionview/test/template/form_options_helper_test.rb | 22 |
2 files changed, 23 insertions, 3 deletions
diff --git a/actionview/lib/action_view/helpers/form_options_helper.rb b/actionview/lib/action_view/helpers/form_options_helper.rb index f625a9ff49..48f42947db 100644 --- a/actionview/lib/action_view/helpers/form_options_helper.rb +++ b/actionview/lib/action_view/helpers/form_options_helper.rb @@ -360,8 +360,8 @@ module ActionView html_attributes = option_html_attributes(element) text, value = option_text_and_value(element).map { |item| item.to_s } - html_attributes[:selected] = option_value_selected?(value, selected) - html_attributes[:disabled] = disabled && option_value_selected?(value, disabled) + html_attributes[:selected] ||= option_value_selected?(value, selected) + html_attributes[:disabled] ||= disabled && option_value_selected?(value, disabled) html_attributes[:value] = value content_tag_string(:option, text, html_attributes) diff --git a/actionview/test/template/form_options_helper_test.rb b/actionview/test/template/form_options_helper_test.rb index 50e9d132a7..fbafb7aa08 100644 --- a/actionview/test/template/form_options_helper_test.rb +++ b/actionview/test/template/form_options_helper_test.rb @@ -119,6 +119,26 @@ class FormOptionsHelperTest < ActionView::TestCase ) end + def test_array_options_for_select_with_custom_defined_selected + assert_dom_equal( + "<option selected=\"selected\" type=\"Coach\" value=\"1\">Richard Bandler</option>\n<option type=\"Coachee\" value=\"1\">Richard Bandler</option>", + options_for_select([ + ['Richard Bandler', 1, { type: 'Coach', selected: 'selected' }], + ['Richard Bandler', 1, { type: 'Coachee' }] + ]) + ) + end + + def test_array_options_for_select_with_custom_defined_disabled + assert_dom_equal( + "<option disabled=\"disabled\" type=\"Coach\" value=\"1\">Richard Bandler</option>\n<option type=\"Coachee\" value=\"1\">Richard Bandler</option>", + options_for_select([ + ['Richard Bandler', 1, { type: 'Coach', disabled: 'disabled' }], + ['Richard Bandler', 1, { type: 'Coachee' }] + ]) + ) + end + def test_array_options_for_select_with_selection assert_dom_equal( "<option value=\"Denmark\">Denmark</option>\n<option value=\"<USA>\" selected=\"selected\"><USA></option>\n<option value=\"Sweden\">Sweden</option>", @@ -813,7 +833,7 @@ class FormOptionsHelperTest < ActionView::TestCase select("post", "category", %w( one two ), :selected => 'two', :prompt => true) ) end - + def test_select_with_disabled_array @post = Post.new @post.category = "<mus>" |