提交 89dc4813 编写于 作者: R Rafael Mendonça França

Merge pull request #7026 from rustygeldmacher/select_options_valid_html_master

Fixed bug creating invalid HTML in select options
......@@ -353,7 +353,7 @@ def options_for_select(container, selected = nil)
html_attributes[:disabled] = 'disabled' if disabled && option_value_selected?(value, disabled)
html_attributes[:value] = value
content_tag(:option, text, html_attributes)
content_tag_string(:option, text, html_attributes)
end.join("\n").html_safe
end
......
......@@ -137,10 +137,10 @@ def select_not_required?(html_options)
def add_options(option_tags, options, value = nil)
if options[:include_blank]
option_tags = content_tag('option', options[:include_blank].kind_of?(String) ? options[:include_blank] : nil, :value => '') + "\n" + option_tags
option_tags = content_tag_string('option', options[:include_blank].kind_of?(String) ? options[:include_blank] : nil, :value => '') + "\n" + option_tags
end
if value.blank? && options[:prompt]
option_tags = content_tag('option', prompt_text(options[:prompt]), :value => '') + "\n" + option_tags
option_tags = content_tag_string('option', prompt_text(options[:prompt]), :value => '') + "\n" + option_tags
end
option_tags
end
......
......@@ -41,6 +41,19 @@ def test_text_field_with_errors
)
end
def test_select_with_errors
assert_dom_equal(
%(<div class="field_with_errors"><select name="post[author_name]" id="post_author_name"><option value="a">a</option>\n<option value="b">b</option></select></div>),
select("post", "author_name", [:a, :b])
)
end
def test_select_with_errors_and_blank_option
expected_dom = %(<div class="field_with_errors"><select name="post[author_name]" id="post_author_name"><option value="">Choose one...</option>\n<option value="a">a</option>\n<option value="b">b</option></select></div>)
assert_dom_equal(expected_dom, select("post", "author_name", [:a, :b], :include_blank => 'Choose one...'))
assert_dom_equal(expected_dom, select("post", "author_name", [:a, :b], :prompt => 'Choose one...'))
end
def test_date_select_with_errors
assert_dom_equal(
%(<div class="field_with_errors"><select id="post_updated_at_1i" name="post[updated_at(1i)]">\n<option selected="selected" value="2004">2004</option>\n<option value="2005">2005</option>\n</select>\n<input id="post_updated_at_2i" name="post[updated_at(2i)]" type="hidden" value="6" />\n<input id="post_updated_at_3i" name="post[updated_at(3i)]" type="hidden" value="1" />\n</div>),
......@@ -82,4 +95,5 @@ def test_field_error_proc
ensure
ActionView::Base.field_error_proc = old_proc if old_proc
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册