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

yulkin
your book suggests to use Image.toByteData() to convert image to bytes, however I get the following error: "the getter ‘toByteData’ isn’t...
New
mikecargal
Title: Hands-on Rust: question about get_component (page 295) (feel free to respond. “You dug you’re own hole… good luck”) I have somet...
New
HarryDeveloper
Hi @venkats, It has been mentioned in the description of ‘Supervisory Job’ title that 2 things as mentioned below result in the same eff...
New
leba0495
Hello! Thanks for the great book. I was attempting the Trie (chap 17) exercises and for number 4 the solution provided for the autocorre...
New
patoncrispy
I’m new to Rust and am using this book to learn more as well as to feed my interest in game dev. I’ve just finished the flappy dragon exa...
New
jskubick
I’m under the impression that when the reader gets to page 136 (“View Data with the Database Inspector”), the code SHOULD be able to buil...
New
jskubick
I found an issue in Chapter 7 regarding android:backgroundTint vs app:backgroundTint. How to replicate: load chapter-7 from zipfile i...
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
creminology
Skimming ahead, much of the following is explained in Chapter 3, but new readers (like me!) will hit a roadblock in Chapter 2 with their ...
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

Other popular topics Top

Devtalk
Hello Devtalk World! Please let us know a little about who you are and where you’re from :nerd_face:
New
New
PragmaticBookshelf
Free and open source software is the default choice for the technologies that run our world, and it’s built and maintained by people like...
New
ohm
Which, if any, games do you play? On what platform? I just bought (and completed) Minecraft Dungeons for my Nintendo Switch. Other than ...
New
dimitarvp
Small essay with thoughts on macOS vs. Linux: I know @Exadra37 is just waiting around the corner to scream at me “I TOLD YOU SO!!!” but I...
New
Margaret
Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
1147 29994 760
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
CommunityNews
A Brief Review of the Minisforum V3 AMD Tablet. Update: I have created an awesome-minisforum-v3 GitHub repository to list information fo...
New
AstonJ
This is a very quick guide, you just need to: Download LM Studio: https://lmstudio.ai/ Click on search Type DeepSeek, then select the o...
New

Sub Categories: