Sorry for the delay, I stripped it down. “Example” is the value being updated.
In my index I have this for the form
defp apply_action(socket, :example, _params) do
example = %Example{}
socket
|> assign(:example, example)
end
In the index I can update the socket value for example using this:
def handle_event("change example", %{"id" => id}, socket) do
example = Examples.get_example!(id)
{:noreply, socket |> assign(:example, example)}
end
My form info
<.live_component
module={ExampleWeb.ExampleLive.FormComponent}
id={"example"}
action={@live_action}
post={@post}
example={@example}
patch={~p"/example"}
/>
@impl true
def update(%{post: post} = assigns, socket) do
changeset = Posts.change_post(post)
{:ok, socket
|> assign(assigns)
|> assign(:changeset, changeset)
|> assign(:uploaded_files, [])
|> allow_upload(:image, accept: ~w(.png .jpeg .jpg), max_entries: 5, max_file_size: 4_194_304, external: &S3Upload.presign_upload/2)
}
end
@impl true
def handle_event("validate", %{"post" => post_params}, socket) do
changeset =
socket.assigns.post
|> Posts.change_post(post_params)
|> Map.put(:action, :validate)
{:noreply, assign(socket, :changeset, changeset)}
end
```<.live_file_input upload={@uploads.image} />
I can update the socket example value and save it to the post with no issues on its own
I can upload a file and save it to the post with no issues on its own.
If I do both however, in either order, it will cause the file_upload to not work.
Other than the error I originally posted I have no feedback with regards to whats going wrong.
If I remove
example={@example}
From the form, I can update the socket and upload files, but I obviously cannot save the example ID as a socket.assigns value.