aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/form_helper.rb
diff options
context:
space:
mode:
authorOlek Janiszewski <olek.janiszewski@gmail.com>2012-02-12 13:32:53 +0100
committerOlek Janiszewski <olek.janiszewski@gmail.com>2012-02-12 16:23:43 +0100
commitd6b26a6040db97a55e23a7f10f2e9ba859eb11dc (patch)
tree490a06d52b15ce36c1d0e1686654fd2cb7f8c0e3 /actionpack/lib/action_view/helpers/form_helper.rb
parent8671802fe8153e82e54b11c64537f5177f8670a3 (diff)
downloadrails-d6b26a6040db97a55e23a7f10f2e9ba859eb11dc.tar.gz
rails-d6b26a6040db97a55e23a7f10f2e9ba859eb11dc.tar.bz2
rails-d6b26a6040db97a55e23a7f10f2e9ba859eb11dc.zip
Add HTML5 input[type="date"] helper
Diffstat (limited to 'actionpack/lib/action_view/helpers/form_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index bdfef920c5..44e24fecd1 100644
--- a/actionpack/lib/action_view/helpers/form_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_helper.rb
@@ -889,6 +889,24 @@ module ActionView
end
alias phone_field telephone_field
+ # Returns a text_field of type "date".
+ #
+ # date_field("user", "born_on")
+ # # => <input id="user_born_on" name="user[born_on]" type="date" />
+ #
+ # The default value is generated by trying to call "to_date"
+ # on the object's value, which makes it behave as expected for instances
+ # of DateTime and ActiveSupport::TimeWithZone. You can still override that
+ # by passing the "value" option explicitly, e.g.
+ #
+ # @user.born_on = Date.new(1984, 1, 27)
+ # date_field("user", "born_on", value: "1984-05-12")
+ # # => <input id="user_born_on" name="user[born_on]" type="date" value="1984-05-12" />
+ #
+ def date_field(object_name, method, options = {})
+ Tags::DateField.new(object_name, method, self, options).render
+ end
+
# Returns a text_field of type "url".
#
# url_field("user", "homepage")