Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I generate input[type=date] with simple_form?

When I do f.input :start_date, as: :date I get 3 select elements (day, month and year).

I can do f.input :start_date, as: :string to get input[type=text] element, but how can I generate input[type=date] element with simple_form?

like image 937
Marcin Doliwa Avatar asked Mar 16 '15 11:03

Marcin Doliwa


2 Answers

You should specify html5 option:

f.input :start_date, as: :date, html5: true

Here is details.

like image 142
Maxim Avatar answered Nov 17 '22 11:11

Maxim


HTML 5 date / time inputs are not generated by Simple Form by default, so using date, time or datetime will all generate select boxes using normal Rails helpers. We believe browsers are not totally ready for these yet, but you can easily opt-in on a per-input basis by passing the html5 option:

<%= f.input :expires_at, as: :date, html5: true %>

Hopefully this piece of information found in simple_form documentation will solve your problem.

like image 14
epergo Avatar answered Nov 17 '22 11:11

epergo