Programming Phoenix LiveView B9: chapter 5 typos (PDF)

The first heex block of code in the section The Promo Live View should just be the <.header>; the code errors out if you include the form here because :changeset isn’t assigned yet.

Like other form blocks, the :let={f} bit isn’t necessary, and the fields should be something like field={@changeset[:name]}. But, to get that to work, the code for assign_changeset on page 132 should be

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

The last bit in handle_event for validate on page 135, also needs to use to_form for the changeset.

allow_upload on page 143: inside the update function, the allow_upload(:image, ...) should show up before assign(:changeset, changeset).

Thanks for pointing these out! You’ll find these form changes alongside all the other upgrades in the next Beta release of the book, coming soon.

Regarding your last comment–there’s no reason that I can see that allow_upload should come before the call to assign the changeset.

Thanks for the update.

I wish I could explain the allow_upload change, but I don’t remember why I needed to do that.
While I kept all my code in a git repo, I only committed changes at the end of chapters, after all the exercises. I went back to the start of the chapter, and worked my way through the text, and everything worked normally without the allow_update change.

I should’ve posted an explanation here. It doesn’t help that my code uses to_form and such everywhere, so it’s already not the same as the book’s.