对于“新”对象表单使用<%= f.datetime_select:start%>时,如何设置选项默认情况下不选择日期,而是使用nil/null值?相关模型中的字段可以有选择地为null,但是默认情况下,datetime_select控件没有null选项。datetime_select没有值?
10
A
回答
27
我想你想:
f.datetime_select :start, :include_blank => true
当start
为零,字段将选择空白选项。这也允许用户而不是输入日期。
有关详细信息,请参阅the documentation for date_select。
0
您将要使用:prompt选项。
从Rails的文档:
# Generates a datetime select with a custom prompt. Use :prompt=>true for generic prompts.
datetime_select("post", "written_on", :prompt => {:day => 'Choose day', :month => 'Choose month', :year => 'Choose year'})
datetime_select("post", "written_on", :prompt => {:hour => true}) # generic prompt for hours
datetime_select("post", "written_on", :prompt => true) # generic prompts for all
相关问题
- 1. Rails datetime_select忽略无效值
- 2. 渲染datetime_select
- 3. form_for with datetime_select
- 4. Rails的datetime_select Mongoid
- 5. Ruby on Rails datetime_select
- 6. 在Sinatra的datetime_select
- 7. datetime_select用归零分钟
- 8. datetime_select不在utc中显示
- 9. Rails 3.2 datetime_select include_blank不按预期工作
- 10. rails在datetime_select选项中刷新日期
- 11. 不能在Mongoid中使用datetime_select
- 12. 在datetime_select中设置end_和start_time形式
- 13. Rails 3:datetime_select与am/pm选项
- 14. 如何设置datetime_select助手的时区
- 15. 有没有空值
- 16. JSONArray没有值
- 17. h:dataTable没有值
- 18. JSONException:pageCount没有值
- 19. 没有价值
- 20. 当没有值使空值
- 21. Sql列没有值
- 22. 没有重复值
- 23. GridView DataBind()没有值
- 24. 没有重复值
- 25. ext.js combobox没有值
- 26. Request.Url.UserInfo没有价值
- 27. xmlConfig.configurationAt没有取值
- 28. JSON PARSE没有值
- 29. Julia中没有值
- 30. 与价值没有
扩展样本似乎没有工作。 <%= f.datetime_select:start,:prompt => {:day =>'选择日期',:month =>'选择月份',:year =>'选择年份'}%> 是否存在语法错误这里? – 2009-02-18 03:40:21
你可以使用香草助手:<%= datetime_select:my_object,:start,:prompt => {:day =>'Choose day',:month =>'选择月份',:year =>'选择年份'} %> – 2009-02-18 11:37:15