Problems with form.html.eex

Currently I need to create a form.html to get the current date.
More gives the error.

** (CompileError) web/templates/disp/form.html.eex:29: undefined function form/0
(stdlib) lists.erl:1338: :lists.foreach/2
(stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
(elixir) lib/kernel/parallel_compiler.ex:117: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/1

How to correct?

My “form.html.eex”

<div class="form-group">
<%= datetime_select f, :data, builder: fn b -> %>
  Date: <%= b.(:day, [date.day]) %> / <%= b.(:month, []) %> / <%= b.(:year, []) %></br></br>
<% end %>
</div>

My “controller”

  def new(conn, _params) do
    changeset = Disp.changeset(%Disp{})
                date = Date.utc_today()
        render(conn, "new.html", changeset: changeset, date: date)
  end

What could it be?

2 Likes

I suspect your problem is this line:

<%= datetime_select f, :data, builder: fn b -> %>

It’s looks like f is not defined. datetime_select should be used within a form_for function. i.e. something like:

<%= form_for @changeset, some_path(@conn, :create), fn f -> %>
  <div class="form-group">
    <%= datetime_select f, :data, builder: fn b -> %>
      ...
    <% end %>
  </div>
<% end %>

See the docs here.

2 Likes

You can also use it out of a form function as well by passing in an id for it to use there instead (on that same documentation page).

2 Likes

This error occurs …
Only when I put the “date.day”

1 Like

I think it would help if you post more of the surrounding code and indicate which is line 29. i.e. the line causing the compiler error).

1 Like