提交 165d93b2 编写于 作者: G Guillermo Iguaran

Merge pull request #14539 from lparedes/master

Do not overwrite selected and disabled attributes
......@@ -360,8 +360,8 @@ def options_for_select(container, selected = nil)
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)
......
......@@ -119,6 +119,26 @@ def test_array_options_for_select
)
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=\"&lt;USA&gt;\" selected=\"selected\">&lt;USA&gt;</option>\n<option value=\"Sweden\">Sweden</option>",
......@@ -813,7 +833,7 @@ def test_select_with_prompt_and_selected_value
select("post", "category", %w( one two ), :selected => 'two', :prompt => true)
)
end
def test_select_with_disabled_array
@post = Post.new
@post.category = "<mus>"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册