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

Change datetime to datetime-local helper tag #25469

Merged
merged 1 commit into from Jun 22, 2016
Jump to file or symbol
Failed to load files and symbols.
+39 −139
Diff settings

Always

Just for now

Copy path View file
@@ -1,3 +1,11 @@
* A change was made in the helper that renders the `datetime`, being now by default `datetime-local` and
creating an alias of `datetime-local` for `datetime`, `datetime` tag and it passes to be an abstract class for all other tags that inherit from him.
As a new specification of the HTML 5 the text field type `datetime` will no longer exist and will pass a `datetime-local`.
Ref: https://html.spec.whatwg.org/multipage/forms.html#local-date-and-time-state-(type=datetime-local)
*Herminio Torres*
* Raw template handler (which is also the default template handler in Rails 5) now outputs
HTML-safe strings.
@@ -1074,68 +1074,37 @@ def time_field(object_name, method, options = {})
Tags::TimeField.new(object_name, method, self, options).render
end
# Returns a text_field of type "datetime".
#
# datetime_field("user", "born_on")
# # => <input id="user_born_on" name="user[born_on]" type="datetime" />
#
# The default value is generated by trying to call +strftime+ with "%Y-%m-%dT%T.%L%z"
# on the object's value, which makes it behave as expected for instances
# of DateTime and ActiveSupport::TimeWithZone.
#
# @user.born_on = Date.new(1984, 1, 12)
# 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 = {})
ActiveSupport::Deprecation.warn(<<-MESSAGE.squish)
datetime_field is deprecated and will be removed in Rails 5.1.
Use datetime_local_field instead.
MESSAGE
Tags::DatetimeField.new(object_name, method, self, options).render
end
# Returns a text_field of type "datetime-local".
#
# datetime_local_field("user", "born_on")
# datetime_field("user", "born_on")
# # => <input id="user_born_on" name="user[born_on]" type="datetime-local" />
#
# The default value is generated by trying to call +strftime+ with "%Y-%m-%dT%T"
# on the object's value, which makes it behave as expected for instances
# of DateTime and ActiveSupport::TimeWithZone.
#
# @user.born_on = Date.new(1984, 1, 12)
# datetime_local_field("user", "born_on")
# datetime_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)
# datetime_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")
# datetime_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 = {})
def datetime_field(object_name, method, options = {})
Tags::DatetimeLocalField.new(object_name, method, self, options).render
end
alias datetime_local_field datetime_field

This comment has been minimized.

@maclover7

maclover7 Jun 22, 2016

Member

Do we need to change the deprecation shipping with 5.0 if we are not deprecating this, and aliasing instead? 😬

# Returns a text_field of type "month".
#
# month_field("user", "born_on")
@@ -685,32 +685,19 @@ def time_field_tag(name, value = nil, options = {})
text_field_tag(name, value, options.merge(type: :time))
end
# Creates a text field of type "datetime".
#
# === Options
# * <tt>:min</tt> - The minimum acceptable value.
# * <tt>:max</tt> - The maximum acceptable value.
# * <tt>:step</tt> - The acceptable value granularity.
# * Otherwise accepts the same options as text_field_tag.
def datetime_field_tag(name, value = nil, options = {})
ActiveSupport::Deprecation.warn(<<-MESSAGE.squish)
datetime_field_tag is deprecated and will be removed in Rails 5.1.
Use datetime_local_field_tag instead.
MESSAGE
text_field_tag(name, value, options.merge(type: :datetime))
end
# Creates a text field of type "datetime-local".
#
# === Options
# * <tt>:min</tt> - The minimum acceptable value.
# * <tt>:max</tt> - The maximum acceptable value.
# * <tt>:step</tt> - The acceptable value granularity.
# * Otherwise accepts the same options as text_field_tag.
def datetime_local_field_tag(name, value = nil, options = {})
def datetime_field_tag(name, value = nil, options = {})
text_field_tag(name, value, options.merge(type: 'datetime-local'))
end
alias datetime_local_field_tag datetime_field_tag
# Creates a text field of type "month".
#
# === Options
@@ -14,7 +14,7 @@ def render
private
def format_date(value)
value.try(:strftime, "%Y-%m-%dT%T.%L%z")
raise NoImplementedError
end
def datetime_value(value)
@@ -1123,129 +1123,67 @@ def test_time_field_with_invalid_string_values_for_min_and_max
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_deprecated do
assert_dom_equal(expected, datetime_field("post", "written_on"))
end
expected = %{<input id="post_written_on" name="post[written_on]" type="datetime-local" value="2004-06-15T00:00:00" />}
assert_dom_equal(expected, datetime_field("post", "written_on"))
end
def test_datetime_field_with_datetime_value
expected = %{<input id="post_written_on" name="post[written_on]" type="datetime" value="2004-06-15T01:02:03.000+0000" />}
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)
assert_deprecated do
assert_dom_equal(expected, datetime_field("post", "written_on"))
end
assert_dom_equal(expected, datetime_field("post", "written_on"))
end
def test_datetime_field_with_extra_attrs
expected = %{<input id="post_written_on" step="60" 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" />}
expected = %{<input id="post_written_on" step="60" 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 = DateTime.new(2000, 6, 15, 20, 45, 30)
max_value = DateTime.new(2010, 8, 15, 10, 25, 00)
step = 60
assert_deprecated do
assert_dom_equal(expected, datetime_field("post", "written_on", min: min_value, max: max_value, step: step))
end
assert_dom_equal(expected, datetime_field("post", "written_on", min: min_value, max: max_value, step: step))
end
def test_datetime_field_with_value_attr
expected = %{<input id="post_written_on" name="post[written_on]" type="datetime" value="2013-06-29T13:37:00+00:00" />}
expected = %{<input id="post_written_on" name="post[written_on]" type="datetime-local" value="2013-06-29T13:37:00+00:00" />}
value = DateTime.new(2013,6,29,13,37)
assert_deprecated do
assert_dom_equal(expected, datetime_field("post", "written_on", value: value))
end
assert_dom_equal(expected, datetime_field("post", "written_on", value: value))
end
def test_datetime_field_with_timewithzone_value
previous_time_zone, Time.zone = Time.zone, 'UTC'
expected = %{<input id="post_written_on" name="post[written_on]" type="datetime" value="2004-06-15T15:30:45.000+0000" />}
expected = %{<input id="post_written_on" name="post[written_on]" type="datetime-local" value="2004-06-15T15:30:45" />}
@post.written_on = Time.zone.parse('2004-06-15 15:30:45')
assert_deprecated do
assert_dom_equal(expected, datetime_field("post", "written_on"))
end
assert_dom_equal(expected, datetime_field("post", "written_on"))
ensure
Time.zone = previous_time_zone
end
def test_datetime_field_with_nil_value
expected = %{<input id="post_written_on" name="post[written_on]" type="datetime" />}
expected = %{<input id="post_written_on" name="post[written_on]" type="datetime-local" />}
@post.written_on = nil
assert_deprecated do
assert_dom_equal(expected, datetime_field("post", "written_on"))
end
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" />}
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.000+0000"
max_value = "2010-08-15T10:25:00.000+0000"
assert_deprecated do
assert_dom_equal(expected, datetime_field("post", "written_on", min: min_value, max: max_value))
end
min_value = "2000-06-15T20:45:30"
max_value = "2010-08-15T10:25:00"
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" />}
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_deprecated do
assert_dom_equal(expected, datetime_field("post", "written_on", min: min_value, max: max_value))
end
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"))
end
def test_datetime_local_field_with_datetime_value
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)
assert_dom_equal(expected, datetime_local_field("post", "written_on"))
end
def test_datetime_local_field_with_extra_attrs
expected = %{<input id="post_written_on" step="60" 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 = DateTime.new(2000, 6, 15, 20, 45, 30)
max_value = DateTime.new(2010, 8, 15, 10, 25, 00)
step = 60
assert_dom_equal(expected, datetime_local_field("post", "written_on", min: min_value, max: max_value, step: step))
end
def test_datetime_local_field_with_timewithzone_value
previous_time_zone, Time.zone = Time.zone, 'UTC'
expected = %{<input id="post_written_on" name="post[written_on]" type="datetime-local" value="2004-06-15T15:30:45" />}
@post.written_on = Time.zone.parse('2004-06-15 15:30:45')
assert_dom_equal(expected, datetime_local_field("post", "written_on"))
ensure
Time.zone = previous_time_zone
end
def test_datetime_local_field_with_nil_value
expected = %{<input id="post_written_on" name="post[written_on]" type="datetime-local" />}
@post.written_on = nil
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"))
@@ -621,10 +621,8 @@ def test_time_field_tag
end
def test_datetime_field_tag
expected = %{<input id="appointment" name="appointment" type="datetime" />}
assert_deprecated do
assert_dom_equal(expected, datetime_field_tag("appointment"))
end
expected = %{<input id="appointment" name="appointment" type="datetime-local" />}
assert_dom_equal(expected, datetime_field_tag("appointment"))
end
def test_datetime_local_field_tag
ProTip! Use n and p to navigate between commits in a pull request.