millisami
millisami

Reputation: 10151

I want a date select box with blank values selected by default

I used the following date_select helpers but none of them shows a date select box with blank values selected by default. With all the following code, I get the select box but with the current date selected. I'm on Rails 2.3.2

<%= f.date_select :featured_at, :default => {:day => nil, :month => nil, :year => nil} %>
<%#= date_select("post", "featured_at", :prompt => { :day => 'Select day', :month => 'Select month', :year => 'Select year' }) %>
<%#= date_select("post", "featured_at", :default => { :day => nil }) %>
<%#= f.date_select :featured_at, :include_blank => true, :order => [:day, :month, :year] %>

Upvotes: 11

Views: 13289

Answers (3)

Vedant Agarwala
Vedant Agarwala

Reputation: 18819

Additionally, prompt: true works as well:

<%= f.date_select :deadline, {order: [:day, :month, :year], prompt: true} %>

Better to show day, month, year rather than blank probably in most cases.

Upvotes: 0

Eric
Eric

Reputation: 766

Far easier to do this:

<%= f.date_select :featured_at, {:include_blank => true, :default => nil} %>

Upvotes: 41

philipth
philipth

Reputation: 276

 <%= f.label :expired %><br />
    <%= f.datetime_select :expired,:prompt => { :day => 'Select day', :month => 'Select month', :year => 'Select year' }  %>

works for me

Upvotes: 9

Related Questions