简体   繁体   English

Rails 3.2 Boostrap 3设置Date_Select默认值以提示

[英]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. 我正在使用Bootstrap,但我认为这并不相关。

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. 这段代码的确在选项中添加了“选择日期”等,但默认为nil,因为我的用户的生日是在填写表格时。

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' }  %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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