Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Form input type="date" in Ruby on Rails

I want to have a date input for a form. I know this only works in some browsers:

<input type="date" name="birth_day"/>

Is there a convenient method for this in Ruby on Rails? The documentation for the various form elements list many other input types, but I don't see anything for dates:

  • email_field
  • number_field
  • phone_field
  • range_field
  • search_field
  • telephone_field
  • text_field

I know about date_select, that's not what I want. I want the above HTML output. I'm using Ruby on Rails 3.2.13. Is there possibly a date_field in Ruby on Rails 4? Or another way to do this?

like image 862
at. Avatar asked Apr 09 '13 22:04

at.


People also ask

Is input Type date accessible?

The ones that claim to be accessible aren't. For example, we know <input type="date"> is a problem for voice users across browsers. Graham Armfield already produced a thorough report on the accessibility of the native control and came to conclusion that nope, it is not accessible.

What is form tag in Ruby on Rails?

This can be used for: creating new database records, building a contact form, integrating a search engine field, and pretty much every other aspect of the application that requires user input.


2 Answers

You can see the lastest docs that the date_field helper provide that. That seems a functionality from Rails 4.

Example from docs:

date_field("user", "born_on")
# => <input id="user_born_on" name="user[born_on]" type="date" />
like image 163
Pigueiras Avatar answered Oct 07 '22 07:10

Pigueiras


For older versions of Rails I believe you can use:

.text_field(type: 'date')
like image 30
kanga Avatar answered Oct 07 '22 07:10

kanga