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
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.
Popular Pragmatic Bookshelf topics
Python Testing With Pytest - Chapter 2, warnings for “unregistered custom marks”
While running the smoke tests in Chapter 2, I get these...
New
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
When I try the command to create a pair of migration files I get an error.
user=> (create-migration "guestbook")
Execution error (Ill...
New
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
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
A Common-Sense Guide to Data Structures and Algorithms, Second Edition by Jay Wengrow @jaywengrow
Hi,
I have the paperback version of t...
New
Hi,
I completed chapter 6 but am getting the following error when running:
thread 'main' panicked at 'Failed to load texture: IoError(O...
New
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
@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
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
Bought the Moonlander mechanical keyboard. Cherry Brown MX switches. Arms and wrists have been hurting enough that it’s time I did someth...
New
Learn different ways of writing concurrent code in Elixir and increase your application's performance, without sacrificing scalability or...
New
Think Again 50% Off Sale »
The theme of this sale is new perspectives on familiar topics.
Enter coupon code ThinkAgain2021 at checkout t...
New
Create efficient, elegant software tests in pytest, Python's most powerful testing framework.
Brian Okken @brianokken
Edited by Kat...
New
Author Spotlight
Jamis Buck
@jamis
This month, we have the pleasure of spotlighting author Jamis Buck, who has written Mazes for Prog...
New
Author Spotlight
Erin Dees
@undees
Welcome to our new author spotlight! We had the pleasure of chatting with Erin Dees, co-author of ...
New
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
Author Spotlight:
Bruce Tate
@redrapids
Programming languages always emerge out of need, and if that’s not always true, they’re defin...
New
Explore the power of Ash Framework by modeling and building the domain for a real-world web application.
Rebecca Le @sevenseacat and ...
New
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
Categories:
Sub Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /python
- /js
- /rails
- /security
- /go
- /swift
- /vim
- /clojure
- /java
- /emacs
- /haskell
- /svelte
- /onivim
- /typescript
- /kotlin
- /c-plus-plus
- /crystal
- /tailwind
- /react
- /gleam
- /ocaml
- /flutter
- /elm
- /vscode
- /ash
- /html
- /opensuse
- /zig
- /centos
- /deepseek
- /php
- /scala
- /react-native
- /lisp
- /textmate
- /sublime-text
- /debian
- /nixos
- /agda
- /django
- /deno
- /kubuntu
- /arch-linux
- /nodejs
- /revery
- /ubuntu
- /manjaro
- /spring
- /lua
- /diversity
- /julia
- /markdown
- /slackware









