Programming Phoenix LiveView: promo form requires "to_form" changes (p133)

The schemaless form defined in file “lib/pento_web/live/promo_live.html.heex” on page 133 of the book requires some transformation. The :let={f} syntax no longer works.

In my understanding the changeset needs to be transformed using “to_form()” function, and the the syntax for the input fields has to be adapted too.

in “lib/pento_web/live/promo_live.ex”:

  def assign_changeset(%{assigns: %{recipient: recipient}} = socket) do
    socket
    |> assign(:form, to_form(Promo.change_recipient(recipient)))
  end    

And in “lib/pento_web/live/promo_live.html.heex”:

    <.input field={@form[:first_name]} type="text" label="First Name" />
    <.input field={@form[:email]} type="email"
      label="Email" phx-debounce="blur" />

I’m not 100% there yet, but now the form shows.

3 Likes