Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
ac44345d
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,发现更多精彩内容 >>
提交
ac44345d
编写于
5月 20, 2014
作者:
T
Todd Bealmear
提交者:
Rafael Mendonça França
6月 30, 2014
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add String support for min/max attributes on DatetimeField
上级
dc67d3d2
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
119 addition
and
2 deletion
+119
-2
actionview/lib/action_view/helpers/form_helper.rb
actionview/lib/action_view/helpers/form_helper.rb
+48
-0
actionview/lib/action_view/helpers/tags/datetime_field.rb
actionview/lib/action_view/helpers/tags/datetime_field.rb
+7
-2
actionview/test/template/form_helper_test.rb
actionview/test/template/form_helper_test.rb
+64
-0
未找到文件。
actionview/lib/action_view/helpers/form_helper.rb
浏览文件 @
ac44345d
...
...
@@ -1013,6 +1013,18 @@ def telephone_field(object_name, method, options = {})
# date_field("user", "born_on", value: "1984-05-12")
# # => <input id="user_born_on" name="user[born_on]" type="date" value="1984-05-12" />
#
# You can create values for the "min" and "max" attributes by passing
# instances of Date or Time to the options hash.
#
# date_field("user", "born_on", min: Date.today)
# # => <input id="user_born_on" name="user[born_on]" type="date" min="2014-05-20" />
#
# Alternatively, you can pass a String formatted as an ISO8601 date as the
# values for "min" and "max."
#
# date_field("user", "born_on", min: "2014-05-20")
# # => <input id="user_born_on" name="user[born_on]" type="date" min="2014-05-20" />
#
def
date_field
(
object_name
,
method
,
options
=
{})
Tags
::
DateField
.
new
(
object_name
,
method
,
self
,
options
).
render
end
...
...
@@ -1030,6 +1042,18 @@ def date_field(object_name, method, options = {})
# time_field("task", "started_at")
# # => <input id="task_started_at" name="task[started_at]" type="time" />
#
# You can create values for the "min" and "max" attributes by passing
# instances of Date or Time to the options hash.
#
# time_field("task", "started_at", min: Time.now)
# # => <input id="task_started_at" name="task[started_at]" type="time" min="01:00:00.000" />
#
# Alternatively, you can pass a String formatted as an ISO8601 time as the
# values for "min" and "max."
#
# time_field("task", "started_at", min: "01:00:00")
# # => <input id="task_started_at" name="task[started_at]" type="time" min="01:00:00.000" />
#
def
time_field
(
object_name
,
method
,
options
=
{})
Tags
::
TimeField
.
new
(
object_name
,
method
,
self
,
options
).
render
end
...
...
@@ -1047,6 +1071,18 @@ def time_field(object_name, method, options = {})
# datetime_field("user", "born_on")
# # => <input id="user_born_on" name="user[born_on]" type="datetime" value="1984-01-12T00:00:00.000+0000" />
#
# You can create values for the "min" and "max" attributes by passing
# instances of Date or Time to the options hash.
#
# datetime_field("user", "born_on", min: Date.today)
# # => <input id="user_born_on" name="user[born_on]" type="datetime" min="2014-05-20T00:00:00.000+0000" />
#
# Alternatively, you can pass a String formatted as an ISO8601 datetime
# with UTC offset as the values for "min" and "max."
#
# datetime_field("user", "born_on", min: "2014-05-20T00:00:00+0000")
# # => <input id="user_born_on" name="user[born_on]" type="datetime" min="2014-05-20T00:00:00.000+0000" />
#
def
datetime_field
(
object_name
,
method
,
options
=
{})
Tags
::
DatetimeField
.
new
(
object_name
,
method
,
self
,
options
).
render
end
...
...
@@ -1064,6 +1100,18 @@ def datetime_field(object_name, method, options = {})
# datetime_local_field("user", "born_on")
# # => <input id="user_born_on" name="user[born_on]" type="datetime-local" value="1984-01-12T00:00:00" />
#
# You can create values for the "min" and "max" attributes by passing
# instances of Date or Time to the options hash.
#
# datetime_local_field("user", "born_on", min: Date.today)
# # => <input id="user_born_on" name="user[born_on]" type="datetime-local" min="2014-05-20T00:00:00.000" />
#
# Alternatively, you can pass a String formatted as an ISO8601 datetime as
# the values for "min" and "max."
#
# datetime_local_field("user", "born_on", min: "2014-05-20T00:00:00")
# # => <input id="user_born_on" name="user[born_on]" type="datetime-local" min="2014-05-20T00:00:00.000" />
#
def
datetime_local_field
(
object_name
,
method
,
options
=
{})
Tags
::
DatetimeLocalField
.
new
(
object_name
,
method
,
self
,
options
).
render
end
...
...
actionview/lib/action_view/helpers/tags/datetime_field.rb
浏览文件 @
ac44345d
...
...
@@ -5,8 +5,8 @@ class DatetimeField < TextField # :nodoc:
def
render
options
=
@options
.
stringify_keys
options
[
"value"
]
||=
format_date
(
value
(
object
))
options
[
"min"
]
=
format_date
(
options
[
"min"
]
)
options
[
"max"
]
=
format_date
(
options
[
"max"
]
)
options
[
"min"
]
=
format_date
(
datetime_value
(
options
[
"min"
])
)
options
[
"max"
]
=
format_date
(
datetime_value
(
options
[
"max"
])
)
@options
=
options
super
end
...
...
@@ -16,6 +16,11 @@ def render
def
format_date
(
value
)
value
.
try
(
:strftime
,
"%Y-%m-%dT%T.%L%z"
)
end
def
datetime_value
(
value
)
return
value
unless
value
.
is_a?
String
DateTime
.
parse
(
value
)
rescue
nil
end
end
end
end
...
...
actionview/test/template/form_helper_test.rb
浏览文件 @
ac44345d
...
...
@@ -776,6 +776,22 @@ def test_date_field_with_nil_value
assert_dom_equal
(
expected
,
date_field
(
"post"
,
"written_on"
))
end
def
test_date_field_with_string_values_for_min_and_max
expected
=
%{<input id="post_written_on" max="2010-08-15" min="2000-06-15" name="post[written_on]" type="date" value="2004-06-15" />}
@post
.
written_on
=
DateTime
.
new
(
2004
,
6
,
15
)
min_value
=
"2000-06-15"
max_value
=
"2010-08-15"
assert_dom_equal
(
expected
,
date_field
(
"post"
,
"written_on"
,
min:
min_value
,
max:
max_value
))
end
def
test_date_field_with_invalid_string_values_for_min_and_max
expected
=
%{<input id="post_written_on" name="post[written_on]" type="date" value="2004-06-15" />}
@post
.
written_on
=
DateTime
.
new
(
2004
,
6
,
15
,
1
,
2
,
3
)
min_value
=
"foo"
max_value
=
"bar"
assert_dom_equal
(
expected
,
date_field
(
"post"
,
"written_on"
,
min:
min_value
,
max:
max_value
))
end
def
test_time_field
expected
=
%{<input id="post_written_on" name="post[written_on]" type="time" value="00:00:00.000" />}
assert_dom_equal
(
expected
,
time_field
(
"post"
,
"written_on"
))
...
...
@@ -811,6 +827,22 @@ def test_time_field_with_nil_value
assert_dom_equal
(
expected
,
time_field
(
"post"
,
"written_on"
))
end
def
test_time_field_with_string_values_for_min_and_max
expected
=
%{<input id="post_written_on" max="10:25:00.000" min="20:45:30.000" name="post[written_on]" type="time" value="01:02:03.000" />}
@post
.
written_on
=
DateTime
.
new
(
2004
,
6
,
15
,
1
,
2
,
3
)
min_value
=
"20:45:30.000"
max_value
=
"10:25:00.000"
assert_dom_equal
(
expected
,
time_field
(
"post"
,
"written_on"
,
min:
min_value
,
max:
max_value
))
end
def
test_time_field_with_invalid_string_values_for_min_and_max
expected
=
%{<input id="post_written_on" name="post[written_on]" type="time" value="01:02:03.000" />}
@post
.
written_on
=
DateTime
.
new
(
2004
,
6
,
15
,
1
,
2
,
3
)
min_value
=
"foo"
max_value
=
"bar"
assert_dom_equal
(
expected
,
time_field
(
"post"
,
"written_on"
,
min:
min_value
,
max:
max_value
))
end
def
test_datetime_field
expected
=
%{<input id="post_written_on" name="post[written_on]" type="datetime" value="2004-06-15T00:00:00.000+0000" />}
assert_dom_equal
(
expected
,
datetime_field
(
"post"
,
"written_on"
))
...
...
@@ -852,6 +884,22 @@ def test_datetime_field_with_nil_value
assert_dom_equal
(
expected
,
datetime_field
(
"post"
,
"written_on"
))
end
def
test_datetime_field_with_string_values_for_min_and_max
expected
=
%{<input id="post_written_on" max="2010-08-15T10:25:00.000+0000" min="2000-06-15T20:45:30.000+0000" name="post[written_on]" type="datetime" value="2004-06-15T01:02:03.000+0000" />}
@post
.
written_on
=
DateTime
.
new
(
2004
,
6
,
15
,
1
,
2
,
3
)
min_value
=
"2000-06-15T20:45:30.000+0000"
max_value
=
"2010-08-15T10:25:00.000+0000"
assert_dom_equal
(
expected
,
datetime_field
(
"post"
,
"written_on"
,
min:
min_value
,
max:
max_value
))
end
def
test_datetime_field_with_invalid_string_values_for_min_and_max
expected
=
%{<input id="post_written_on" name="post[written_on]" type="datetime" value="2004-06-15T01:02:03.000+0000" />}
@post
.
written_on
=
DateTime
.
new
(
2004
,
6
,
15
,
1
,
2
,
3
)
min_value
=
"foo"
max_value
=
"bar"
assert_dom_equal
(
expected
,
datetime_field
(
"post"
,
"written_on"
,
min:
min_value
,
max:
max_value
))
end
def
test_datetime_local_field
expected
=
%{<input id="post_written_on" name="post[written_on]" type="datetime-local" value="2004-06-15T00:00:00" />}
assert_dom_equal
(
expected
,
datetime_local_field
(
"post"
,
"written_on"
))
...
...
@@ -887,6 +935,22 @@ def test_datetime_local_field_with_nil_value
assert_dom_equal
(
expected
,
datetime_local_field
(
"post"
,
"written_on"
))
end
def
test_datetime_local_field_with_string_values_for_min_and_max
expected
=
%{<input id="post_written_on" max="2010-08-15T10:25:00" min="2000-06-15T20:45:30" name="post[written_on]" type="datetime-local" value="2004-06-15T01:02:03" />}
@post
.
written_on
=
DateTime
.
new
(
2004
,
6
,
15
,
1
,
2
,
3
)
min_value
=
"2000-06-15T20:45:30"
max_value
=
"2010-08-15T10:25:00"
assert_dom_equal
(
expected
,
datetime_local_field
(
"post"
,
"written_on"
,
min:
min_value
,
max:
max_value
))
end
def
test_datetime_local_field_with_invalid_string_values_for_min_and_max
expected
=
%{<input id="post_written_on" name="post[written_on]" type="datetime-local" value="2004-06-15T01:02:03" />}
@post
.
written_on
=
DateTime
.
new
(
2004
,
6
,
15
,
1
,
2
,
3
)
min_value
=
"foo"
max_value
=
"bar"
assert_dom_equal
(
expected
,
datetime_local_field
(
"post"
,
"written_on"
,
min:
min_value
,
max:
max_value
))
end
def
test_month_field
expected
=
%{<input id="post_written_on" name="post[written_on]" type="month" value="2004-06" />}
assert_dom_equal
(
expected
,
month_field
(
"post"
,
"written_on"
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录