aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Rowe <hello@jonrowe.co.uk>2013-06-28 13:44:31 +1000
committerJon Rowe <hello@jonrowe.co.uk>2013-06-29 19:32:13 +1000
commit53eb9fdd9c546b101b22e1711ed0c3dd3df19197 (patch)
tree386b4acc9697891d98c0312915c227c5fbcef99a
parent9a26d94d60d626f3d4d71909455fce1ef2b1a99c (diff)
downloadrails-53eb9fdd9c546b101b22e1711ed0c3dd3df19197.tar.gz
rails-53eb9fdd9c546b101b22e1711ed0c3dd3df19197.tar.bz2
rails-53eb9fdd9c546b101b22e1711ed0c3dd3df19197.zip
fetch value(s) from stringified options
-rw-r--r--actionview/CHANGELOG.md4
-rw-r--r--actionview/lib/action_view/helpers/tags/color_field.rb2
-rw-r--r--actionview/lib/action_view/helpers/tags/datetime_field.rb2
-rw-r--r--actionview/test/template/form_helper_test.rb17
4 files changed, 23 insertions, 2 deletions
diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md
index 543367a216..a89070c910 100644
--- a/actionview/CHANGELOG.md
+++ b/actionview/CHANGELOG.md
@@ -1,3 +1,7 @@
+* Pick `DateField` `DateTimeField` and `ColorField` values from stringified options allowing use of symbol keys with helpers.
+
+ *Jon Rowe*
+
* Remove the deprecated `prompt` argument from `grouped_options_for_select`,
pass in a `:prompt` hash option to use this feature.
diff --git a/actionview/lib/action_view/helpers/tags/color_field.rb b/actionview/lib/action_view/helpers/tags/color_field.rb
index d8fc797035..bab28352ed 100644
--- a/actionview/lib/action_view/helpers/tags/color_field.rb
+++ b/actionview/lib/action_view/helpers/tags/color_field.rb
@@ -4,7 +4,7 @@ module ActionView
class ColorField < TextField # :nodoc:
def render
options = @options.stringify_keys
- options["value"] = @options.fetch("value") { validate_color_string(value(object)) }
+ options["value"] = options.fetch("value") { validate_color_string(value(object)) }
@options = options
super
end
diff --git a/actionview/lib/action_view/helpers/tags/datetime_field.rb b/actionview/lib/action_view/helpers/tags/datetime_field.rb
index 9a2279c611..416d225706 100644
--- a/actionview/lib/action_view/helpers/tags/datetime_field.rb
+++ b/actionview/lib/action_view/helpers/tags/datetime_field.rb
@@ -4,7 +4,7 @@ module ActionView
class DatetimeField < TextField # :nodoc:
def render
options = @options.stringify_keys
- options["value"] = @options.fetch("value") { format_date(value(object)) }
+ options["value"] = options.fetch("value") { format_date(value(object)) }
options["min"] = format_date(options["min"])
options["max"] = format_date(options["max"])
@options = options
diff --git a/actionview/test/template/form_helper_test.rb b/actionview/test/template/form_helper_test.rb
index 1ff320224d..db44b00ef6 100644
--- a/actionview/test/template/form_helper_test.rb
+++ b/actionview/test/template/form_helper_test.rb
@@ -702,6 +702,11 @@ class FormHelperTest < ActionView::TestCase
assert_dom_equal(expected, color_field("car", "color"))
end
+ def test_color_field_with_value_attr
+ expected = %{<input id="car_color" name="car[color]" type="color" value="#00FF00" />}
+ assert_dom_equal(expected, color_field("car", "color", value: "#00FF00"))
+ end
+
def test_search_field
expected = %{<input id="contact_notes_query" name="contact[notes_query]" type="search" />}
assert_dom_equal(expected, search_field("contact", "notes_query"))
@@ -732,6 +737,12 @@ class FormHelperTest < ActionView::TestCase
assert_dom_equal(expected, date_field("post", "written_on", min: min_value, max: max_value, step: step))
end
+ def test_date_field_with_value_attr
+ expected = %{<input id="post_written_on" name="post[written_on]" type="date" value="2013-06-29" />}
+ value = Date.new(2013,6,29)
+ assert_dom_equal(expected, date_field("post", "written_on", value: value))
+ end
+
def test_date_field_with_timewithzone_value
previous_time_zone, Time.zone = Time.zone, 'UTC'
expected = %{<input id="post_written_on" name="post[written_on]" type="date" value="2004-06-15" />}
@@ -802,6 +813,12 @@ class FormHelperTest < ActionView::TestCase
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" />}
+ value = DateTime.new(2013,6,29,13,37)
+ 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" />}