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

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
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
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
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
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

We're in Beta

About us Mission Statement