gpt4 book ai didi

elixir - 将 phoenix 框架中日期选择器的默认值设置为当前日期

转载 作者:行者123 更新时间:2023-12-04 23:19:51 31 4
gpt4 key购买 nike

在我正在开发的应用程序中,我有一个日期选择器,它主要用于将当前日期作为值(或几天后的日期)。为了减少我的用户的工作,我想将今天的日期设置为默认值。

我可以轻松地设置年份: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"] ,
但这些都没有奏效。更换 defaultvalue没有区别。我犯了什么错误?

提前致谢

最佳答案

根据文档,默认选项直接提供给 date_select。所以这应该有效:

date_select f, :date, default: {@current_year, 2, 13}

您也可以使用其他格式传递日期,例如 map 而不是元组。 Check datetime_select docs for the accepted formats .

关于elixir - 将 phoenix 框架中日期选择器的默认值设置为当前日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30424156/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com