4
votes

I am using simple_form to generate date input like so:

= f.input :date_of_death

However, it always pre-populates with the current date.

How can I have it come up "blank" and allow the user to easily NOT enter a date?

Thanks!

3

3 Answers

4
votes

There are a couple of ways to do this while still keeping the form split into dropdowns for Y/M/D.

= f.input :date_of_death, include_blank: true

Or if you want the first option to have text use prompt.

= f.input :date_of_death, prompt: "Choose Wisely"
0
votes

Simplest way that I have found

f.input :date_of_death, as: :string

It will turn the input into a blank input field. You will have to parse the string as a date in your controller.

0
votes

Use include_blank

= f.input :fecha_at, include_blank: true, start_year: Date.today.year - 90, end_year: Date.today.year