The*_*uts 4 elixir phoenix-framework
在我正在开发的应用程序中,我有一个日期选择器,主要用于当前日期作为值(或几天后的日期).为了减少用户的工作量,我想将今天的日期设置为默认值.
我可以轻松地设置年份:
date_select f, :date, class="form_control", year: [options: @current_year, @current_year+1],但是没有设法做出类似的月份和日期.
我试着改变代码date_select f, :date, class="form_control", year: [options: @current_year, @current_year+1], month: [default: 2],
date_select f, :date, class="form_control", year: [options: @current_year, @current_year+1], month: [default: "2"],
date_select f, :date, class="form_control", year: [options: @current_year, @current_year+1], month: [default: "02"],但这些都不奏效.更换default有value没有什么区别.我犯了什么错误?
提前致谢
根据文档,默认选项直接提供给date_select.所以这应该工作:
date_select f, :date, default: {@current_year, 2, 13}
Run Code Online (Sandbox Code Playgroud)
您也可以使用其他格式传递日期,例如地图而不是元组.检查datetime_select文档以了解可接受的格式.