Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
6617d018
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,发现更多精彩内容 >>
提交
6617d018
编写于
5月 15, 2010
作者:
J
Jeff Dean
提交者:
José Valim
5月 15, 2010
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Sending :id => nil to form helpers now properly omits the "id" html element [#4559 state:resolved]
Signed-off-by:
N
José Valim
<
jose.valim@gmail.com
>
上级
d6cbb27e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
118 addition
and
5 deletion
+118
-5
actionpack/lib/action_view/helpers/form_helper.rb
actionpack/lib/action_view/helpers/form_helper.rb
+11
-5
actionpack/test/template/form_helper_test.rb
actionpack/test/template/form_helper_test.rb
+107
-0
未找到文件。
actionpack/lib/action_view/helpers/form_helper.rb
浏览文件 @
6617d018
...
...
@@ -859,7 +859,13 @@ def to_label_tag(text = nil, options = {}, &block)
options
=
options
.
stringify_keys
tag_value
=
options
.
delete
(
"value"
)
name_and_id
=
options
.
dup
name_and_id
[
"id"
]
=
name_and_id
[
"for"
]
if
name_and_id
[
"for"
]
name_and_id
[
"id"
]
=
name_and_id
[
"for"
]
else
name_and_id
.
delete
(
"id"
)
end
add_default_name_and_id_for_value
(
tag_value
,
name_and_id
)
options
.
delete
(
"index"
)
options
[
"for"
]
||=
name_and_id
[
"id"
]
...
...
@@ -1027,7 +1033,7 @@ def add_default_name_and_id_for_value(tag_value, options)
pretty_tag_value
=
tag_value
.
to_s
.
gsub
(
/\s/
,
"_"
).
gsub
(
/\W/
,
""
).
downcase
specified_id
=
options
[
"id"
]
add_default_name_and_id
(
options
)
options
[
"id"
]
+=
"_
#{
pretty_tag_value
}
"
unless
specified_id
options
[
"id"
]
+=
"_
#{
pretty_tag_value
}
"
if
specified_id
.
blank?
&&
options
[
"id"
].
present?
else
add_default_name_and_id
(
options
)
end
...
...
@@ -1036,14 +1042,14 @@ def add_default_name_and_id_for_value(tag_value, options)
def
add_default_name_and_id
(
options
)
if
options
.
has_key?
(
"index"
)
options
[
"name"
]
||=
tag_name_with_index
(
options
[
"index"
])
options
[
"id"
]
||=
tag_id_with_index
(
options
[
"index"
]
)
options
[
"id"
]
=
options
.
fetch
(
"id"
,
tag_id_with_index
(
options
[
"index"
])
)
options
.
delete
(
"index"
)
elsif
defined?
(
@auto_index
)
options
[
"name"
]
||=
tag_name_with_index
(
@auto_index
)
options
[
"id"
]
||=
tag_id_with_index
(
@auto_index
)
options
[
"id"
]
=
options
.
fetch
(
"id"
,
tag_id_with_index
(
@auto_index
)
)
else
options
[
"name"
]
||=
tag_name
+
(
options
.
has_key?
(
'multiple'
)
?
'[]'
:
''
)
options
[
"id"
]
||=
tag_id
options
[
"id"
]
=
options
.
fetch
(
"id"
,
tag_id
)
end
end
...
...
actionpack/test/template/form_helper_test.rb
浏览文件 @
6617d018
...
...
@@ -423,6 +423,90 @@ def test_explicit_id
check_box
(
"post"
,
"secret"
,
:id
=>
"i mean it"
)
end
def
test_nil_id
assert_dom_equal
(
'<input name="post[title]" size="30" type="text" value="Hello World" />'
,
text_field
(
"post"
,
"title"
,
"id"
=>
nil
)
)
assert_dom_equal
(
'<textarea cols="40" name="post[body]" rows="20">Back to the hill and over it again!</textarea>'
,
text_area
(
"post"
,
"body"
,
"id"
=>
nil
)
)
assert_dom_equal
(
'<input name="post[secret]" type="hidden" value="0" /><input checked="checked" name="post[secret]" type="checkbox" value="1" />'
,
check_box
(
"post"
,
"secret"
,
"id"
=>
nil
)
)
assert_dom_equal
(
'<input type="radio" name="post[secret]" value="0" />'
,
radio_button
(
"post"
,
"secret"
,
"0"
,
"id"
=>
nil
)
)
assert_dom_equal
(
'<select name="post[secret]"></select>'
,
select
(
"post"
,
"secret"
,
[],
{},
"id"
=>
nil
)
)
assert_dom_equal
text_field
(
"post"
,
"title"
,
"id"
=>
nil
),
text_field
(
"post"
,
"title"
,
:id
=>
nil
)
assert_dom_equal
text_area
(
"post"
,
"body"
,
"id"
=>
nil
),
text_area
(
"post"
,
"body"
,
:id
=>
nil
)
assert_dom_equal
check_box
(
"post"
,
"secret"
,
"id"
=>
nil
),
check_box
(
"post"
,
"secret"
,
:id
=>
nil
)
assert_dom_equal
radio_button
(
"post"
,
"secret"
,
"id"
=>
nil
),
radio_button
(
"post"
,
"secret"
,
:id
=>
nil
)
end
def
test_index
assert_dom_equal
(
'<input name="post[5][title]" size="30" id="post_5_title" type="text" value="Hello World" />'
,
text_field
(
"post"
,
"title"
,
"index"
=>
5
)
)
assert_dom_equal
(
'<textarea cols="40" name="post[5][body]" id="post_5_body" rows="20">Back to the hill and over it again!</textarea>'
,
text_area
(
"post"
,
"body"
,
"index"
=>
5
)
)
assert_dom_equal
(
'<input name="post[5][secret]" type="hidden" value="0" /><input checked="checked" name="post[5][secret]" type="checkbox" value="1" id="post_5_secret" />'
,
check_box
(
"post"
,
"secret"
,
"index"
=>
5
)
)
assert_dom_equal
(
text_field
(
"post"
,
"title"
,
"index"
=>
5
),
text_field
(
"post"
,
"title"
,
"index"
=>
5
)
)
assert_dom_equal
(
text_area
(
"post"
,
"body"
,
"index"
=>
5
),
text_area
(
"post"
,
"body"
,
"index"
=>
5
)
)
assert_dom_equal
(
check_box
(
"post"
,
"secret"
,
"index"
=>
5
),
check_box
(
"post"
,
"secret"
,
"index"
=>
5
)
)
end
def
test_index_with_nil_id
assert_dom_equal
(
'<input name="post[5][title]" size="30" type="text" value="Hello World" />'
,
text_field
(
"post"
,
"title"
,
"index"
=>
5
,
'id'
=>
nil
)
)
assert_dom_equal
(
'<textarea cols="40" name="post[5][body]" rows="20">Back to the hill and over it again!</textarea>'
,
text_area
(
"post"
,
"body"
,
"index"
=>
5
,
'id'
=>
nil
)
)
assert_dom_equal
(
'<input name="post[5][secret]" type="hidden" value="0" /><input checked="checked" name="post[5][secret]" type="checkbox" value="1" />'
,
check_box
(
"post"
,
"secret"
,
"index"
=>
5
,
'id'
=>
nil
)
)
assert_dom_equal
(
text_field
(
"post"
,
"title"
,
"index"
=>
5
,
'id'
=>
nil
),
text_field
(
"post"
,
"title"
,
:index
=>
5
,
:id
=>
nil
)
)
assert_dom_equal
(
text_area
(
"post"
,
"body"
,
"index"
=>
5
,
'id'
=>
nil
),
text_area
(
"post"
,
"body"
,
:index
=>
5
,
:id
=>
nil
)
)
assert_dom_equal
(
check_box
(
"post"
,
"secret"
,
"index"
=>
5
,
'id'
=>
nil
),
check_box
(
"post"
,
"secret"
,
:index
=>
5
,
:id
=>
nil
)
)
end
def
test_auto_index
pid
=
@post
.
id
assert_dom_equal
(
...
...
@@ -449,6 +533,29 @@ def test_auto_index
)
end
def
test_auto_index_with_nil_id
pid
=
@post
.
id
assert_dom_equal
(
"<input name=
\"
post[
#{
pid
}
][title]
\"
size=
\"
30
\"
type=
\"
text
\"
value=
\"
Hello World
\"
/>"
,
text_field
(
"post[]"
,
"title"
,
:id
=>
nil
)
)
assert_dom_equal
(
"<textarea cols=
\"
40
\"
name=
\"
post[
#{
pid
}
][body]
\"
rows=
\"
20
\"
>Back to the hill and over it again!</textarea>"
,
text_area
(
"post[]"
,
"body"
,
:id
=>
nil
)
)
assert_dom_equal
(
"<input name=
\"
post[
#{
pid
}
][secret]
\"
type=
\"
hidden
\"
value=
\"
0
\"
/><input checked=
\"
checked
\"
name=
\"
post[
#{
pid
}
][secret]
\"
type=
\"
checkbox
\"
value=
\"
1
\"
/>"
,
check_box
(
"post[]"
,
"secret"
,
:id
=>
nil
)
)
assert_dom_equal
(
"<input checked=
\"
checked
\"
name=
\"
post[
#{
pid
}
][title]
\"
type=
\"
radio
\"
value=
\"
Hello World
\"
/>"
,
radio_button
(
"post[]"
,
"title"
,
"Hello World"
,
:id
=>
nil
)
)
assert_dom_equal
(
"<input name=
\"
post[
#{
pid
}
][title]
\"
type=
\"
radio
\"
value=
\"
Goodbye World
\"
/>"
,
radio_button
(
"post[]"
,
"title"
,
"Goodbye World"
,
:id
=>
nil
)
)
end
def
test_form_for
assert_deprecated
do
form_for
(
:post
,
@post
,
:html
=>
{
:id
=>
'create-post'
})
do
|
f
|
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录