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

After, playing with it what worked for me is

<.input field={f[:first_name} type="text" label="First Name" />

But I feel like my way is incorrect or hacky at least.

Thanks so much for calling this out. I’m working through the book and this saved me quite a bit of time.

Full updates to this and all other forms coming soon! We’re hard at work on a new book version and it should be available for download in the next few weeks.