How to use phoenix inputs_for on phoenix 1.7 now?

Hello, I’m trying to create a form but my form use a changeset with embeed schema like:

  name: "Name",
  address:  %{
    name: "Street Alpha",
    number: 412
    postal_code: 12312321

How to do the same without input_for like 1.6 version? Thank you.

yeah strange I have the same issue here, actually ist should come from Phoenix.HTML right? seems like no functions from this module are available somehow

1 Like

ok its from Phoenix.HTML.Form, so you can

import Phoenix.HTML.Form

e.g. in MyAppWeb.html_helpers

1 Like

Hmmm Ok. But I understood that we should use components from core_components.ex where it’s all components now.
I don’t know if we should continue using this Phoenix.HTML

Did you ever manage to figure out how to use inputs_for with the new core components? I’m trying to follow the Contexts guide for 1.7.0-rc.2 and I’m having a hard time to make it work.

Do we still need to use Phoenix.HTML.Form.inputs_for and <.form /> or is there another way of doing it with the simple_form component?

Okay, I think I got it. Not sure if this is the best way but I made it work using core components:

<.simple_form :let={f} for={@changeset} action={~p"/cart"}>
    <li :for={item_form <- inputs_for(f, :items)}>
      <% item = %>
      <%= hidden_inputs_for(item_form) %>
      <%= item.product.title %>
      <.input field={{item_form, :quantity}} type="number" label="Quantity" />
      <%= currency_to_str(ShoppingCart.total_item_price(item)) %>

    <.button>update cart</.button>

Your prayers have been answered @wceolin Add `<.inputs_for />` by LostKobrakai · Pull Request #2404 · phoenixframework/phoenix_live_view · GitHub

1 Like