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

jesse050717
Title: Web Development with Clojure, Third Edition, pg 116 Hi - I just started chapter 5 and I am stuck on page 116 while trying to star...
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
AndyDavis3416
@noelrappin Running the webpack dev server, I receive the following warning: ERROR in tsconfig.json TS18003: No inputs were found in c...
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
akraut
The markup used to display the uploaded image results in a Phoenix.LiveView.HTMLTokenizer.ParseError error. lib/pento_web/live/product_l...
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
jwandekoken
Book: Programming Phoenix LiveView, page 142 (157/378), file lib/pento_web/live/product_live/form_component.ex, in the function below: d...
New
Keton
When running the program in chapter 8, “Implementing Combat”, the printout Health before attack was never printed so I assumed something ...
New
New
bjnord
Hello @herbert ! Trying to get the very first “Hello, Bracket Terminal!" example to run (p. 53). I develop on an Amazon EC2 instance runn...
New

Other popular topics Top

PragmaticBookshelf
Design and develop sophisticated 2D games that are as much fun to make as they are to play. From particle effects and pathfinding to soci...
New
AstonJ
Curious to know which languages and frameworks you’re all thinking about learning next :upside_down_face: Perhaps if there’s enough peop...
New
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
rustkas
Intensively researching Erlang books and additional resources on it, I have found that the topic of using Regular Expressions is either c...
New
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
PragmaticBookshelf
Author Spotlight Rebecca Skinner @RebeccaSkinner Welcome to our latest author spotlight, where we sit down with Rebecca Skinner, auth...
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
PragmaticBookshelf
Explore the power of Ash Framework by modeling and building the domain for a real-world web application. Rebecca Le @sevenseacat and ...
New

Sub Categories: