简体   繁体   中英

Rails 3.2 Boostrap 3 Set Date_Select default value to prompt

I would like to have my date select fields default to "Select month", "Select dat", and "Select year"

I've read that you can not combine default with prompt because default doesn't recognize prompt. I'm using Bootstrap but I don't believe that is very relevant.

This code does add "Select day", etc to the options but it is defaulting to nil since that what my user's birthdate is at the time of the form.

Is there a straightforward solution? Seems like a common problem.

        <%= ff.date_select :birth_date, prompt: true, 
        :prompt => { :day => 'Select day', :month => 'Select month', :year => 'Select year' },
        include_blank: true, 
        :default => {:year=>"Select year", :month=>"Select month", :day=>"Select day"} %>

You cannot use the prompt twice, as one is enough. Try this and let me know.

<%= ff.date_select :birth_date,:prompt => { :day => 'Select day', :month => 'Select month', :year => 'Select year' }  %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM