Skip to content

Commit

Permalink
Merge pull request #14539 from lparedes/master
Browse files Browse the repository at this point in the history
Do not overwrite selected and disabled attributes
Conflicts:
	actionpack/lib/action_view/helpers/form_options_helper.rb
  • Loading branch information
guilleiguaran committed Mar 31, 2014
1 parent 17ddc1b commit 9310741
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions actionpack/lib/action_view/helpers/form_options_helper.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ def options_for_select(container, selected = nil)
html_attributes = option_html_attributes(element) html_attributes = option_html_attributes(element)
text, value = option_text_and_value(element).map { |item| item.to_s } text, value = option_text_and_value(element).map { |item| item.to_s }


html_attributes[:selected] = 'selected' if option_value_selected?(value, selected) html_attributes[:selected] ||= 'selected' if option_value_selected?(value, selected)
html_attributes[:disabled] = 'disabled' if disabled && option_value_selected?(value, disabled) html_attributes[:disabled] ||= 'disabled' if disabled && option_value_selected?(value, disabled)
html_attributes[:value] = value html_attributes[:value] = value


content_tag_string(:option, text, html_attributes) content_tag_string(:option, text, html_attributes)
Expand Down
20 changes: 20 additions & 0 deletions actionpack/test/template/form_options_helper_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -122,6 +122,26 @@ def test_array_options_for_select
) )
end 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 def test_array_options_for_select_with_selection
assert_dom_equal( assert_dom_equal(
"<option value=\"Denmark\">Denmark</option>\n<option value=\"&lt;USA&gt;\" selected=\"selected\">&lt;USA&gt;</option>\n<option value=\"Sweden\">Sweden</option>", "<option value=\"Denmark\">Denmark</option>\n<option value=\"&lt;USA&gt;\" selected=\"selected\">&lt;USA&gt;</option>\n<option value=\"Sweden\">Sweden</option>",
Expand Down

0 comments on commit 9310741

Please sign in to comment.