Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nil value on datetime_select?

When using <%= f.datetime_select :start %> for a "new" object form, how can you set the options to not select a date by default but rather a nil/null value? The field in the related model can optionally be null but by default the datetime_select control doesn't have a null option.

like image 625
Michael Glenn Avatar asked Feb 18 '09 02:02

Michael Glenn


1 Answers

I think you want:

f.datetime_select :start, :include_blank => true

When start is nil, the fields will select the blank option. This also allows users to not enter a date.

See the documentation for date_select for details.

like image 75
Luke Francl Avatar answered Oct 25 '22 00:10

Luke Francl