arcanemachine

arcanemachine

Programming Phoenix LiveView B9.0: (Form Episode 3) Form code syntax does not work as written (p. 216/217) (PDF)

This is the same issue as this one (I’ll call it Form Episode 2) and this one (I’ll call it Form Episode 1). Unsurprisingly, it requires the same solution as the other 2 issues.

On page 216/217, the following code produces an error:

    <.input field={{f, :user_id}} type="hidden" />
    <.input field={{f, :product_id}} type="hidden" />
    <.input field={{f, :stars}} type="rating" prompt="Rating"
    options={["★★★★★": 5, "★★★★": 4, "★★★": 3, "★★": 2, "★": 1
    ]} />

The error reads:

key :name not found in: %{
  id: nil,
  label: nil,
  type: "hidden",
  prompt: nil,
  field: {%Phoenix.HTML.Form{
     source: #Ecto.Changeset<
       action: nil,
       changes: %{},
       errors: [stars: {"can't be blank", [validation: :required]}],
       data: #Pento.Survey.Rating<>,
       valid?: false
     >,
     impl: Phoenix.HTML.FormData.Ecto.Changeset,
     id: "rating-form-1",
     name: "rating",
     data: %Pento.Survey.Rating{
       __meta__: #Ecto.Schema.Metadata<:built, "ratings">,
       id: nil,
       stars: nil,
       user_id: 1,
       user: #Ecto.Association.NotLoaded<association :user is not loaded>,
       product_id: 1,
       product: #Ecto.Association.NotLoaded<association :product is not loaded>,
       inserted_at: nil,
       updated_at: nil
     },
     hidden: [],
     params: %{},
     errors: [],
     options: [
       method: "post",
       id: "rating-form-1",
       multipart: false,
       "phx-target": %Phoenix.LiveComponent.CID{cid: 1},
       "phx-submit": "save"
     ],
     index: nil,
     action: nil
   }, :user_id},
  errors: [],
  rest: %{},
  __changed__: nil,
  inner_block: [],
  __given__: %{
    type: "hidden",
    field: {%Phoenix.HTML.Form{
       source: #Ecto.Changeset<
         action: nil,
         changes: %{},
         errors: [stars: {"can't be blank", [validation: :required]}],
         data: #Pento.Survey.Rating<>,
         valid?: false
       >,
       impl: Phoenix.HTML.FormData.Ecto.Changeset,
       id: "rating-form-1",
       name: "rating",
       data: %Pento.Survey.Rating{
         __meta__: #Ecto.Schema.Metadata<:built, "ratings">,
         id: nil,
         stars: nil,
         user_id: 1,
         user: #Ecto.Association.NotLoaded<association :user is not loaded>,
         product_id: 1,
         product: #Ecto.Association.NotLoaded<association :product is not loaded>,
         inserted_at: nil,
         updated_at: nil
       },
       hidden: [],
       params: %{},
       errors: [],
       options: [
         method: "post",
         id: "rating-form-1",
         multipart: false,
         "phx-target": %Phoenix.LiveComponent.CID{cid: 1},
         "phx-submit": "save"
       ],
       index: nil,
       action: nil
     }, :user_id},
    __changed__: nil
  },
  multiple: false
}

To fix the error, change the offending lines to read:

    <.input field={f[:user_id]} type="hidden" />
    <.input field={f[:product_id]} type="hidden" />
    <.input field={f[:stars]} type="rating" prompt="Rating"
    options={["★★★★★": 5, "★★★★": 4, "★★★": 3, "★★": 2, "★": 1
    ]} />

Marked As Solved

SophieDeBenedetto

SophieDeBenedetto

Author of Programming Phoenix LiveView

Thanks for your feedback here. This and all other forms are being updated to work with the latest version of LiveView as we speak. We’ll be release a new Beta version of the book in the next few weeks.

Where Next?

Popular Pragmatic Bookshelf topics Top

telemachus
Python Testing With Pytest - Chapter 2, warnings for “unregistered custom marks” While running the smoke tests in Chapter 2, I get these...
New
brianokken
Many tasks_proj/tests directories exist in chapters 2, 3, 5 that have tests that use the custom markers smoke and get, which are not decl...
New
simonpeter
When I try the command to create a pair of migration files I get an error. user=&gt; (create-migration "guestbook") Execution error (Ill...
New
JohnS
I can’t setup the Rails source code. This happens in a working directory containing multiple (postgres) Rails apps. With: ruby-3.0.0 s...
New
raul
Page 28: It implements io.ReaderAt on the store type. Sorry if it’s a dumb question but was the io.ReaderAt supposed to be io.ReadAt? ...
New
New
oaklandgit
Hi, I completed chapter 6 but am getting the following error when running: thread 'main' panicked at 'Failed to load texture: IoError(O...
New
Henrai
Hi, I’m working on the Chapter 8 of the book. After I add add the point_offset, I’m still able to see acne: In the image above, I re...
New
mcpierce
@mfazio23 I’ve applied the changes from Chapter 5 of the book and everything builds correctly and runs. But, when I try to start a game,...
New
dachristenson
I’ve got to the end of Ch. 11, and the app runs, with all tabs displaying what they should – at first. After switching around between St...
New

Other popular topics Top

brentjanderson
Bought the Moonlander mechanical keyboard. Cherry Brown MX switches. Arms and wrists have been hurting enough that it’s time I did someth...
New
PragmaticBookshelf
Learn different ways of writing concurrent code in Elixir and increase your application's performance, without sacrificing scalability or...
New
New
PragmaticBookshelf
Create efficient, elegant software tests in pytest, Python's most powerful testing framework. Brian Okken @brianokken Edited by Kat...
New
PragmaticBookshelf
Author Spotlight Jamis Buck @jamis This month, we have the pleasure of spotlighting author Jamis Buck, who has written Mazes for Prog...
New
New
PragmaticBookshelf
Author Spotlight: VM Brasseur @vmbrasseur We have a treat for you today! We turn the spotlight onto Open Source as we sit down with V...
New
New
PragmaticBookshelf
Explore the power of Ash Framework by modeling and building the domain for a real-world web application. Rebecca Le @sevenseacat and ...
New
mindriot
Ok, well here are some thoughts and opinions on some of the ergonomic keyboards I have, I guess like mini review of each that I use enoug...
New

Sub Categories: