I feel like I'll never wrap my head around form handling stuff. I have this liveview where I'm trying to create a minimal form:
defmodule MatrixControllerWeb.Test2Live do
use MatrixControllerWeb, :live_view
require Logger
@impl true
def mount(_params, _session, socket) do
options = %{
0 => "Zero",
1 => "One"
}
socket =
socket
|> assign(options: options)
|> assign(form: to_form(%{"option" => 0}))
{:ok, socket}
end
@impl true
def render(assigns) do
~H"""
<.form
for={@form}
phx-submit="connect">
<br />
<.input
field={@form[:option]}
type="select"
options={@options} />
<button>Submit</button>
</.form>
"""
end
end
Whenever I load the page the input component gives me an error saying "key :name not found in: (...assigns)". I can manually add all the keys that it complains about, but that seems to defeat the point. What am I missing?