提交 2d8c10a7 编写于 作者: K Kasper Timm Hansen

Merge pull request #29412 from y-yagi/fix_29014

Generate field ids in `collection_check_boxes` and `collection_radio_buttons`
上级 457c1278
* Generate field ids in `collection_check_boxes` and `collection_radio_buttons`.
This makes sure that the labels are linked up with the fields.
Fixes #29014.
*Yuji Yaginuma*
## Rails 5.1.1 (May 12, 2017) ##
* No changes.
......
......@@ -10,6 +10,7 @@ class CheckBoxBuilder < Builder # :nodoc:
def check_box(extra_html_options = {})
html_options = extra_html_options.merge(@input_html_options)
html_options[:multiple] = true
html_options[:skip_default_ids] = false
@template_object.check_box(@object_name, @method_name, html_options, @value, nil)
end
end
......
......@@ -9,6 +9,7 @@ class CollectionRadioButtons < Base # :nodoc:
class RadioButtonBuilder < Builder # :nodoc:
def radio_button(extra_html_options = {})
html_options = extra_html_options.merge(@input_html_options)
html_options[:skip_default_ids] = false
@template_object.radio_button(@object_name, @method_name, @value, html_options)
end
end
......
......@@ -403,9 +403,9 @@ def post.active; false; end
expected = whole_form("/posts") do
"<input type='hidden' name='post[active]' value='' />" \
"<input name='post[active]' type='radio' value='true' />" \
"<input name='post[active]' type='radio' value='true' id='post_active_true' />" \
"<label for='post_active_true'>true</label>" \
"<input checked='checked' name='post[active]' type='radio' value='false' />" \
"<input checked='checked' name='post[active]' type='radio' value='false' id='post_active_false' />" \
"<label for='post_active_false'>false</label>"
end
......@@ -426,10 +426,10 @@ def post.active; false; end
expected = whole_form("/posts") do
"<input type='hidden' name='post[active]' value='' />" \
"<label for='post_active_true'>" \
"<input name='post[active]' type='radio' value='true' />" \
"<input name='post[active]' type='radio' value='true' id='post_active_true' />" \
"true</label>" \
"<label for='post_active_false'>" \
"<input checked='checked' name='post[active]' type='radio' value='false' />" \
"<input checked='checked' name='post[active]' type='radio' value='false' id='post_active_false' />" \
"false</label>"
end
......@@ -452,10 +452,10 @@ def post.id; 1; end
expected = whole_form("/posts") do
"<input type='hidden' name='post[active]' value='' />" \
"<label for='post_active_true'>" \
"<input name='post[active]' type='radio' value='true' />" \
"<input name='post[active]' type='radio' value='true' id='post_active_true' />" \
"true</label>" \
"<label for='post_active_false'>" \
"<input checked='checked' name='post[active]' type='radio' value='false' />" \
"<input checked='checked' name='post[active]' type='radio' value='false' id='post_active_false' />" \
"false</label>" \
"<input name='post[id]' type='hidden' value='1' />"
end
......@@ -473,9 +473,9 @@ def post.active; false; end
expected = whole_form("/posts") do
"<input type='hidden' name='post[1][active]' value='' />" \
"<input name='post[1][active]' type='radio' value='true' />" \
"<input name='post[1][active]' type='radio' value='true' id='post_1_active_true' />" \
"<label for='post_1_active_true'>true</label>" \
"<input checked='checked' name='post[1][active]' type='radio' value='false' />" \
"<input checked='checked' name='post[1][active]' type='radio' value='false' id='post_1_active_false' />" \
"<label for='post_1_active_false'>false</label>"
end
......@@ -492,11 +492,11 @@ def post.tag_ids; [1, 3]; end
expected = whole_form("/posts") do
"<input name='post[tag_ids][]' type='hidden' value='' />" \
"<input checked='checked' name='post[tag_ids][]' type='checkbox' value='1' />" \
"<input checked='checked' name='post[tag_ids][]' type='checkbox' value='1' id='post_tag_ids_1' />" \
"<label for='post_tag_ids_1'>Tag 1</label>" \
"<input name='post[tag_ids][]' type='checkbox' value='2' />" \
"<input name='post[tag_ids][]' type='checkbox' value='2' id='post_tag_ids_2' />" \
"<label for='post_tag_ids_2'>Tag 2</label>" \
"<input checked='checked' name='post[tag_ids][]' type='checkbox' value='3' />" \
"<input checked='checked' name='post[tag_ids][]' type='checkbox' value='3' id='post_tag_ids_3' />" \
"<label for='post_tag_ids_3'>Tag 3</label>"
end
......@@ -517,13 +517,13 @@ def post.tag_ids; [1, 3]; end
expected = whole_form("/posts") do
"<input name='post[tag_ids][]' type='hidden' value='' />" \
"<label for='post_tag_ids_1'>" \
"<input checked='checked' name='post[tag_ids][]' type='checkbox' value='1' />" \
"<input checked='checked' name='post[tag_ids][]' type='checkbox' value='1' id='post_tag_ids_1' />" \
"Tag 1</label>" \
"<label for='post_tag_ids_2'>" \
"<input name='post[tag_ids][]' type='checkbox' value='2' />" \
"<input name='post[tag_ids][]' type='checkbox' value='2' id='post_tag_ids_2' />" \
"Tag 2</label>" \
"<label for='post_tag_ids_3'>" \
"<input checked='checked' name='post[tag_ids][]' type='checkbox' value='3' />" \
"<input checked='checked' name='post[tag_ids][]' type='checkbox' value='3' id='post_tag_ids_3' />" \
"Tag 3</label>"
end
......@@ -547,13 +547,13 @@ def post.id; 1; end
expected = whole_form("/posts") do
"<input name='post[tag_ids][]' type='hidden' value='' />" \
"<label for='post_tag_ids_1'>" \
"<input checked='checked' name='post[tag_ids][]' type='checkbox' value='1' />" \
"<input checked='checked' name='post[tag_ids][]' type='checkbox' value='1' id='post_tag_ids_1' />" \
"Tag 1</label>" \
"<label for='post_tag_ids_2'>" \
"<input name='post[tag_ids][]' type='checkbox' value='2' />" \
"<input name='post[tag_ids][]' type='checkbox' value='2' id='post_tag_ids_2' />" \
"Tag 2</label>" \
"<label for='post_tag_ids_3'>" \
"<input checked='checked' name='post[tag_ids][]' type='checkbox' value='3' />" \
"<input checked='checked' name='post[tag_ids][]' type='checkbox' value='3' id='post_tag_ids_3' />" \
"Tag 3</label>" \
"<input name='post[id]' type='hidden' value='1' />"
end
......@@ -572,7 +572,7 @@ def post.tag_ids; [1]; end
expected = whole_form("/posts") do
"<input name='post[1][tag_ids][]' type='hidden' value='' />" \
"<input checked='checked' name='post[1][tag_ids][]' type='checkbox' value='1' />" \
"<input checked='checked' name='post[1][tag_ids][]' type='checkbox' value='1' id='post_1_tag_ids_1' />" \
"<label for='post_1_tag_ids_1'>Tag 1</label>"
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册