简体   繁体   English

如何在 Elixir/Phoenix 中为文本输入提供默认值?

[英]How can I give a text input a default value in Elixir/Phoenix?

I have this field我有这个领域

  <%= number_input f, :duration_minutes %>

and I would like to give it a default of 60. How can I do that?我想给它一个默认值 60。我该怎么做?

The obvious guess of显而易见的猜测

  <%= number_input f, :duration_minutes, default: 60 %>

didn't work.没用。

Update based on the comment from Allen:根据艾伦的评论更新:

  schema "events" do
    field :duration_minutes, :integer, default: 60
  end

Here is my previous answer that isn't as robust according to him:这是我之前的回答,他认为这不是那么可靠:

  <%= number_input f, :duration_minutes, value: 60 %>

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

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