Pistrie

Pistrie

Programming Phoenix LiveView: What should the Rating form look like? (page 216/217)

Currently the component looks like this:

<div>
  <.form :let={f} for={@changeset} phx-submit="save" phx-target={@myself} id={@id}>
    <.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
      ]}
    />
    <.button phx-disable-with="Saving...">Save</.button>
  </.form>
</div>

However this gives me the following error:

Long error inside key :name not found in: %{__changed__: nil, __given__: %{__changed__: nil, field: {%Phoenix.HTML.Form{source: #Ecto.Changeset, 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, product_id: 1, product: #Ecto.Association.NotLoaded, inserted_at: nil, updated_at: nil}, hidden: [], params: %{}, errors: [], options: [method: "post", id: "rating-form-1", multipart: false, "phx-submit": "save", "phx-target": %Phoenix.LiveComponent.CID{cid: 1}], index: nil, action: nil}, :user_id}, type: "hidden"}, errors: [], field: {%Phoenix.HTML.Form{source: #Ecto.Changeset, 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, product_id: 1, product: #Ecto.Association.NotLoaded, inserted_at: nil, updated_at: nil}, hidden: [], params: %{}, errors: [], options: [method: "post", id: "rating-form-1", multipart: false, "phx-submit": "save", "phx-target": %Phoenix.LiveComponent.CID{cid: 1}], index: nil, action: nil}, :user_id}, id: nil, inner_block: [], label: nil, multiple: false, prompt: nil, rest: %{}, type: "hidden"}

What do I do to fix this?

Marked As Solved

SophieDeBenedetto

SophieDeBenedetto

Author of Programming Phoenix LiveView

The code in the book is working off of an outdated version of LiveView, and you appear to be using a newer version. You might find some help here Programming Phoenix LiveView: promo form requires "to_form" changes (p133) - #4 by SophieDeBenedetto. We are currently hard at work on an upgraded version of the whole book which will available for download in the next few weeks so stay tuned!

Popular Prag Prog 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
Alexandr
Hi everyone! There is an error on the page 71 in the book “Programming machine learning from coding to depp learning” P. Perrotta. You c...
New
sdmoralesma
Title: Web Development with Clojure, Third Edition - migrations/create not working: p159 When I execute the command: user=&gt; (create-...
New
mikecargal
Title: Hands-On Rust (Chap 8 (Adding a Heads Up Display) It looks like ​.with_simple_console_no_bg​(SCREEN_WIDTH*2, SCREEN_HEIGHT*2...
New
gilesdotcodes
In case this helps anyone, I’ve had issues setting up the rails source code. Here were the solutions: In Gemfile, change gem 'rails' t...
New
leonW
I ran this command after installing the sample application: $ cards add do something --owner Brian And got a file not found error: Fil...
New
brunogirin
When installing Cards as an editable package, I get the following error: ERROR: File “setup.py” not found. Directory cannot be installe...
New
a.zampa
@mfazio23 I’m following the indications of the book and arriver ad chapter 10, but the app cannot be compiled due to an error in the Bas...
New
New
redconfetti
Docker-Machine became part of the Docker Toolbox, which was deprecated in 2020, long after Docker Desktop supported Docker Engine nativel...
New

Other popular topics Top

Devtalk
Reading something? Working on something? Planning something? Changing jobs even!? If you’re up for sharing, please let us know what you’...
1016 16828 371
New
Exadra37
On modern versions of macOS, you simply can’t power on your computer, launch a text editor or eBook reader, and write or read, without a ...
New
Exadra37
I am asking for any distro that only has the bare-bones to be able to get a shell in the server and then just install the packages as we ...
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
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
First poster: bot
The overengineered Solution to my Pigeon Problem. TL;DR: I built a wifi-equipped water gun to shoot the pigeons on my balcony, controlle...
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
Author Spotlight: Tammy Coron @Paradox927 Gaming, and writing games in particular, is about passion, vision, experience, and immersio...
New
New

Latest in PragProg

View all threads ❯