phoenixframework/phoenix_ecto

Problem with nested input with version 4.2.1

ChristopheBelpaire opened this issue · 7 comments

Hello,
I had a kind of bug when I upgraded from version 4.1.0 to 4.2.1 .

I'm using the following nested form :


  <div class="columns">
    <div class="column">
      <%= input f, :reference, required: true %>
    </div>
    <div class="column">
      <%= input f, :date, using: :datepicker %>
    </div>
  </div>

  <div class="field" style="margin-top: 2rem;">
    <label class="label">Fabrication Orders</label>

    <div class="columns is-vcentered is-variable is-1" style="margin-bottom: 0;">
      <div class="column is-1"></div>
      <div class="column has-text-centered">Product Model</div>
      <div class="column is-2 has-text-centered">Quantity</div>
      <div class="column is-2 has-text-centered">Assigned</div>
      <div class="column is-1"></div>
    </div>

    <%= for fabrication_order_form <- inputs_for(f, :fabrication_orders) do %>
        <%= hidden_inputs_for(fabrication_order_form) %>

        <div class="columns is-vcentered is-variable is-1" style="margin-bottom: 0;">

And I have the following error after upgrade :
lib/phoenix_ecto/html.ex

     {prepend, opts} = Keyword.pop(opts, :prepend, [])
      {append, opts} = Keyword.pop(opts, :append, [])
      {name, opts} = Keyword.pop(opts, :as)
      {id, opts} = Keyword.pop(opts, :id)
      id = to_string(id || form.id <> "_#{field}")
      name = to_string(name || form.name <> "[#{field}]")
      case find_inputs_for_type!(source, field) do
        {:one, cast, module} ->
          changesets =

It is fixed if I add an ID to my input_for :

    <%= for fabrication_order_form <- inputs_for(f, :fabrication_orders, id: :nested_input) do %>

Did I miss something or is it a bug ? :)

Thanks in advance!

And I have the following error after upgrade :

I think you forgot to add the actual error you are seeing? :)

Hello,
the statcktrace is :

     {prepend, opts} = Keyword.pop(opts, :prepend, [])
      {append, opts} = Keyword.pop(opts, :append, [])
      {name, opts} = Keyword.pop(opts, :as)
      {id, opts} = Keyword.pop(opts, :id)
      id = to_string(id || form.id <> "_#{field}")
      name = to_string(name || form.name <> "[#{field}]")
      case find_inputs_for_type!(source, field) do
        {:one, cast, module} ->
          changesets = ....

Capture d’écran 2021-03-03 à 18 32 40

Better with a screenshot maybe :)

Thanks. I need more information to reproduce this. How is the form being created? I believe the form id should always be set as long as you start building the form from a changeset. Otherwise you need to pass the :id.

Hello again!
Thanks for looking at the issue :)
Ok, I made an example to reproduce the problem here :
https://github.com/ChristopheBelpaire/phoenix_ecto_issue_137
If the form_for and the input_for both have an id, everything is fine.
If the form_for has an id but the form_for doesn't, it crash.
I just noticed it because I had this case and it was fine in the previous version of phoenix_ecto.

Oh, it took me a while but I understand the issue now. ID must be a string. I will improve the error messages here. :) Thanks!

Also thanks a lot for the app reproducing the issue :)

And thanks a lot for fixing it! :)