Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
7e583b73
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7e583b73
编写于
12月 31, 2015
作者:
S
Santiago Pastorino
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix collection_radio_buttons' hidden_field name and make it appear before the radios
Fixes #22773
上级
b238dd73
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
42 addition
and
26 deletion
+42
-26
actionview/CHANGELOG.md
actionview/CHANGELOG.md
+8
-0
actionview/lib/action_view/helpers/tags/collection_check_boxes.rb
...ew/lib/action_view/helpers/tags/collection_check_boxes.rb
+4
-0
actionview/lib/action_view/helpers/tags/collection_helpers.rb
...onview/lib/action_view/helpers/tags/collection_helpers.rb
+6
-2
actionview/test/template/form_collections_helper_test.rb
actionview/test/template/form_collections_helper_test.rb
+6
-6
actionview/test/template/form_helper_test.rb
actionview/test/template/form_helper_test.rb
+18
-18
未找到文件。
actionview/CHANGELOG.md
浏览文件 @
7e583b73
*
Fix
`collection_radio_buttons`
hidden_field name and make it appear
before the actual input radio tags to make the real value override
the hidden when passed.
Fixes #22773
*Santiago Pastorino*
*
`ActionView::TestCase::Controller#params`
returns an instance of
`ActionController::Parameters`
.
...
...
actionview/lib/action_view/helpers/tags/collection_check_boxes.rb
浏览文件 @
7e583b73
...
...
@@ -23,6 +23,10 @@ def render(&block)
def
render_component
(
builder
)
builder
.
check_box
+
builder
.
label
end
def
hidden_field_name
#:nodoc:
"
#{
super
}
[]"
end
end
end
end
...
...
actionview/lib/action_view/helpers/tags/collection_helpers.rb
浏览文件 @
7e583b73
...
...
@@ -97,16 +97,20 @@ def render_collection_for(builder_class, &block) #:nodoc:
# Append a hidden field to make sure something will be sent back to the
# server if all radio buttons are unchecked.
if
options
.
fetch
(
'include_hidden'
,
true
)
rendered_collection
+
hidden_field
hidden_field
+
rendered_collection
else
rendered_collection
end
end
def
hidden_field
#:nodoc:
hidden_name
=
@html_options
[
:name
]
||
"
#{
tag_name
(
false
,
@options
[
:index
])
}
[]"
hidden_name
=
@html_options
[
:name
]
||
hidden_field_name
@template_object
.
hidden_field_tag
(
hidden_name
,
""
,
id:
nil
)
end
def
hidden_field_name
#:nodoc:
"
#{
tag_name
(
false
,
@options
[
:index
])
}
"
end
end
end
end
...
...
actionview/test/template/form_collections_helper_test.rb
浏览文件 @
7e583b73
...
...
@@ -202,35 +202,35 @@ def with_collection_check_boxes(*args, &block)
collection
=
[
Category
.
new
(
1
,
'Category 1'
),
Category
.
new
(
2
,
'Category 2'
)]
with_collection_radio_buttons
:user
,
:category_ids
,
collection
,
:id
,
:name
assert_select
"input[type=hidden][name='user[category_ids]
[]
'][value='']"
,
count:
1
assert_select
"input[type=hidden][name='user[category_ids]'][value='']"
,
count:
1
end
test
'collection radio buttons generates a hidden field using the given :name in :html_options'
do
collection
=
[
Category
.
new
(
1
,
'Category 1'
),
Category
.
new
(
2
,
'Category 2'
)]
with_collection_radio_buttons
:user
,
:category_ids
,
collection
,
:id
,
:name
,
{},
{
name:
"user[other_category_ids]
[]
"
}
with_collection_radio_buttons
:user
,
:category_ids
,
collection
,
:id
,
:name
,
{},
{
name:
"user[other_category_ids]"
}
assert_select
"input[type=hidden][name='user[other_category_ids]
[]
'][value='']"
,
count:
1
assert_select
"input[type=hidden][name='user[other_category_ids]'][value='']"
,
count:
1
end
test
'collection radio buttons generates a hidden field with index if it was provided'
do
collection
=
[
Category
.
new
(
1
,
'Category 1'
),
Category
.
new
(
2
,
'Category 2'
)]
with_collection_radio_buttons
:user
,
:category_ids
,
collection
,
:id
,
:name
,
{
index:
322
}
assert_select
"input[type=hidden][name='user[322][category_ids]
[]
'][value='']"
,
count:
1
assert_select
"input[type=hidden][name='user[322][category_ids]'][value='']"
,
count:
1
end
test
'collection radio buttons does not generate a hidden field if include_hidden option is false'
do
collection
=
[
Category
.
new
(
1
,
'Category 1'
),
Category
.
new
(
2
,
'Category 2'
)]
with_collection_radio_buttons
:user
,
:category_ids
,
collection
,
:id
,
:name
,
include_hidden:
false
assert_select
"input[type=hidden][name='user[category_ids]
[]
'][value='']"
,
count:
0
assert_select
"input[type=hidden][name='user[category_ids]'][value='']"
,
count:
0
end
test
'collection radio buttons does not generate a hidden field if include_hidden option is false with key as string'
do
collection
=
[
Category
.
new
(
1
,
'Category 1'
),
Category
.
new
(
2
,
'Category 2'
)]
with_collection_radio_buttons
:user
,
:category_ids
,
collection
,
:id
,
:name
,
'include_hidden'
=>
false
assert_select
"input[type=hidden][name='user[category_ids]
[]
'][value='']"
,
count:
0
assert_select
"input[type=hidden][name='user[category_ids]'][value='']"
,
count:
0
end
# COLLECTION CHECK BOXES
...
...
actionview/test/template/form_helper_test.rb
浏览文件 @
7e583b73
...
...
@@ -1600,11 +1600,11 @@ def post.active; false; end
end
expected
=
whole_form
(
"/posts"
,
"new_post"
,
"new_post"
)
do
"<input type='hidden' name='post[active]' value='' />"
+
"<input id='post_active_true' name='post[active]' type='radio' value='true' />"
+
"<label for='post_active_true'>true</label>"
+
"<input checked='checked' id='post_active_false' name='post[active]' type='radio' value='false' />"
+
"<label for='post_active_false'>false</label>"
+
"<input type='hidden' name='post[active][]' value='' />"
"<label for='post_active_false'>false</label>"
end
assert_dom_equal
expected
,
output_buffer
...
...
@@ -1622,13 +1622,13 @@ def post.active; false; end
end
expected
=
whole_form
(
"/posts"
,
"new_post"
,
"new_post"
)
do
"<input type='hidden' name='post[active]' value='' />"
+
"<label for='post_active_true'>"
+
"<input id='post_active_true' name='post[active]' type='radio' value='true' />"
+
"true</label>"
+
"<label for='post_active_false'>"
+
"<input checked='checked' id='post_active_false' name='post[active]' type='radio' value='false' />"
+
"false</label>"
+
"<input type='hidden' name='post[active][]' value='' />"
"false</label>"
end
assert_dom_equal
expected
,
output_buffer
...
...
@@ -1648,13 +1648,13 @@ def post.id; 1; end
end
expected
=
whole_form
(
"/posts"
,
"new_post_1"
,
"new_post"
)
do
"<input type='hidden' name='post[active]' value='' />"
+
"<label for='post_active_true'>"
+
"<input id='post_active_true' name='post[active]' type='radio' value='true' />"
+
"true</label>"
+
"<label for='post_active_false'>"
+
"<input checked='checked' id='post_active_false' name='post[active]' type='radio' value='false' />"
+
"false</label>"
+
"<input type='hidden' name='post[active][]' value='' />"
+
"<input id='post_id' name='post[id]' type='hidden' value='1' />"
end
...
...
@@ -1670,11 +1670,11 @@ def post.active; false; end
end
expected
=
whole_form
(
"/posts"
,
"foo_new_post"
,
"new_post"
)
do
"<input type='hidden' name='post[active]' value='' />"
+
"<input id='foo_post_active_true' name='post[active]' type='radio' value='true' />"
+
"<label for='foo_post_active_true'>true</label>"
+
"<input checked='checked' id='foo_post_active_false' name='post[active]' type='radio' value='false' />"
+
"<label for='foo_post_active_false'>false</label>"
+
"<input type='hidden' name='post[active][]' value='' />"
"<label for='foo_post_active_false'>false</label>"
end
assert_dom_equal
expected
,
output_buffer
...
...
@@ -1689,11 +1689,11 @@ def post.active; false; end
end
expected
=
whole_form
(
"/posts"
,
"new_post"
,
"new_post"
)
do
"<input type='hidden' name='post[1][active]' value='' />"
+
"<input id='post_1_active_true' name='post[1][active]' type='radio' value='true' />"
+
"<label for='post_1_active_true'>true</label>"
+
"<input checked='checked' id='post_1_active_false' name='post[1][active]' type='radio' value='false' />"
+
"<label for='post_1_active_false'>false</label>"
+
"<input type='hidden' name='post[1][active][]' value='' />"
"<label for='post_1_active_false'>false</label>"
end
assert_dom_equal
expected
,
output_buffer
...
...
@@ -1708,13 +1708,13 @@ def post.tag_ids; [1, 3]; end
end
expected
=
whole_form
(
"/posts"
,
"new_post"
,
"new_post"
)
do
"<input name='post[tag_ids][]' type='hidden' value='' />"
+
"<input checked='checked' id='post_tag_ids_1' name='post[tag_ids][]' type='checkbox' value='1' />"
+
"<label for='post_tag_ids_1'>Tag 1</label>"
+
"<input id='post_tag_ids_2' name='post[tag_ids][]' type='checkbox' value='2' />"
+
"<label for='post_tag_ids_2'>Tag 2</label>"
+
"<input checked='checked' id='post_tag_ids_3' name='post[tag_ids][]' type='checkbox' value='3' />"
+
"<label for='post_tag_ids_3'>Tag 3</label>"
+
"<input name='post[tag_ids][]' type='hidden' value='' />"
"<label for='post_tag_ids_3'>Tag 3</label>"
end
assert_dom_equal
expected
,
output_buffer
...
...
@@ -1732,6 +1732,7 @@ def post.tag_ids; [1, 3]; end
end
expected
=
whole_form
(
"/posts"
,
"new_post"
,
"new_post"
)
do
"<input name='post[tag_ids][]' type='hidden' value='' />"
+
"<label for='post_tag_ids_1'>"
+
"<input checked='checked' id='post_tag_ids_1' name='post[tag_ids][]' type='checkbox' value='1' />"
+
"Tag 1</label>"
+
...
...
@@ -1740,8 +1741,7 @@ def post.tag_ids; [1, 3]; end
"Tag 2</label>"
+
"<label for='post_tag_ids_3'>"
+
"<input checked='checked' id='post_tag_ids_3' name='post[tag_ids][]' type='checkbox' value='3' />"
+
"Tag 3</label>"
+
"<input name='post[tag_ids][]' type='hidden' value='' />"
"Tag 3</label>"
end
assert_dom_equal
expected
,
output_buffer
...
...
@@ -1762,6 +1762,7 @@ def post.id; 1; end
end
expected
=
whole_form
(
"/posts"
,
"new_post_1"
,
"new_post"
)
do
"<input name='post[tag_ids][]' type='hidden' value='' />"
+
"<label for='post_tag_ids_1'>"
+
"<input checked='checked' id='post_tag_ids_1' name='post[tag_ids][]' type='checkbox' value='1' />"
+
"Tag 1</label>"
+
...
...
@@ -1771,7 +1772,6 @@ def post.id; 1; end
"<label for='post_tag_ids_3'>"
+
"<input checked='checked' id='post_tag_ids_3' name='post[tag_ids][]' type='checkbox' value='3' />"
+
"Tag 3</label>"
+
"<input name='post[tag_ids][]' type='hidden' value='' />"
+
"<input id='post_id' name='post[id]' type='hidden' value='1' />"
end
...
...
@@ -1788,9 +1788,9 @@ def post.tag_ids; [1]; end
end
expected
=
whole_form
(
"/posts"
,
"foo_new_post"
,
"new_post"
)
do
"<input name='post[tag_ids][]' type='hidden' value='' />"
+
"<input checked='checked' id='foo_post_tag_ids_1' name='post[tag_ids][]' type='checkbox' value='1' />"
+
"<label for='foo_post_tag_ids_1'>Tag 1</label>"
+
"<input name='post[tag_ids][]' type='hidden' value='' />"
"<label for='foo_post_tag_ids_1'>Tag 1</label>"
end
assert_dom_equal
expected
,
output_buffer
...
...
@@ -1806,9 +1806,9 @@ def post.tag_ids; [1]; end
end
expected
=
whole_form
(
"/posts"
,
"new_post"
,
"new_post"
)
do
"<input name='post[1][tag_ids][]' type='hidden' value='' />"
+
"<input checked='checked' id='post_1_tag_ids_1' name='post[1][tag_ids][]' type='checkbox' value='1' />"
+
"<label for='post_1_tag_ids_1'>Tag 1</label>"
+
"<input name='post[1][tag_ids][]' type='hidden' value='' />"
"<label for='post_1_tag_ids_1'>Tag 1</label>"
end
assert_dom_equal
expected
,
output_buffer
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录