Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
194 views
in Technique[技术] by (71.8m points)

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?

The obvious guess of

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

didn't work.

question from:https://stackoverflow.com/questions/65855282/how-can-i-give-a-text-input-a-default-value-in-elixir-phoenix

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...