New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add HTML5 input[type="time"] helper #5715
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module ActionView | ||
module Helpers | ||
module Tags | ||
class TimeField < TextField #:nodoc: | ||
def render | ||
options = @options.stringify_keys | ||
options["value"] = @options.fetch("value") { value(object).try(:strftime, "%T.%L") } | ||
@options = options | ||
super | ||
end | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -646,6 +646,32 @@ def test_date_field_with_nil_value | |
assert_dom_equal(expected, date_field("post", "written_on")) | ||
end | ||
|
||
def test_time_field | ||
expected = %{<input id="post_written_on" name="post[written_on]" type="time" value="00:00:00.000" />} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is the value required? I think that if we don't have a value it should be blank. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rafaelfranca you are right, the value isn't required. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. Thank you. |
||
assert_dom_equal(expected, time_field("post", "written_on")) | ||
end | ||
|
||
def test_time_field_with_datetime_value | ||
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) | ||
assert_dom_equal(expected, time_field("post", "written_on")) | ||
end | ||
|
||
def test_time_field_with_timewithzone_value | ||
previous_time_zone, Time.zone = Time.zone, 'UTC' | ||
expected = %{<input id="post_written_on" name="post[written_on]" type="time" value="01:02:03.000" />} | ||
@post.written_on = Time.zone.parse('2004-06-15 01:02:03') | ||
assert_dom_equal(expected, time_field("post", "written_on")) | ||
ensure | ||
Time.zone = previous_time_zone | ||
end | ||
|
||
def test_time_field_with_nil_value | ||
expected = %{<input id="post_written_on" name="post[written_on]" type="time" />} | ||
@post.written_on = nil | ||
assert_dom_equal(expected, time_field("post", "written_on")) | ||
end | ||
|
||
def test_url_field | ||
expected = %{<input id="user_homepage" name="user[homepage]" type="url" />} | ||
assert_dom_equal(expected, url_field("user", "homepage")) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jeremy I've just added fractional seconds to time.