mogadget

mogadget

Nested form using inputs_for is not rendering

I have a relationship User has_one Profile. In my User

defmodule Cal.Accounts.User do
  actions do
      defaults [:read]
      create :create_user_with_profile do
        argument :profile, :map do
          allow_nil? false
        end
        change manage_relationship(:profile, type: :create)
      end
  action

  relationship do
    has_one :profile, Cal.Accounts.Profile do
        destination_attribute :user_profile_id
    end
  end
...
end

In my form liveview

  def mount(_params, _session, socket) do
    form = Cal.Accounts.form_to_create_user_with_profile()
    socket =
      socket
      |> assign(:form, to_form(form))
      |> assign(:page_title, "New User with Profile")
    {:ok, socket}
  end

  def render(assigns) do
     ...
       <h4>User</h4>
        <.input field={form[:email]} label="Email" />
        <.input field={form[:user_name]} label="Name" />
        <.input field={form[:timezone]} label="Timezone" />

        <h4>User Profile</h4>
        <.inputs_for :let={form_profile} field={@form[:profile]}>
          <.input field={form_profile[:title]} label="Title" />
          <.input field={form_profile[:location]} label="Location" />
        </.inputs_for>
   end

The form renders the Email, Name and Timezone but the fields for profile Title and Location are not

First Post!

cmo

cmo

Throw a few inspects in there to see what data you’re getting in render. IIRC <prev>{inspect(@form[:profile], pretty: true)}</pre>.

Last Post!

cmo

cmo

You might want to load the association.

Where Next?

Popular in Questions Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54092 488
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31525 112
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New

We're in Beta

About us Mission Statement