arcanemachine

arcanemachine

Programming Phoenix LiveView B9.0: warning: Passing an atom to "for" in the form component is deprecated. (p. 251)

On page 251, when creating the form components for the admin dashboard, this example code:

<.form
  for={:gender_filter}
  phx-change="gender_filter"
  phx-target={@myself}
  id="gender-form"
>

Produces the following deprecation warning:

warning: Passing an atom to "for" in the form component is deprecated.                                                                
Instead of:

    <.form :let={f} for={:gender_filter} ...>                                                       

You might do:

    <.form :let={f} for={%{}} as={:gender_filter} ...>

Or, if you prefer, use to_form to create a form in your LiveView:
                                                                   
    assign(socket, form: to_form(%{}, as: :gender_filter))

and then use it in your templates (no :let required):

    <.form for={@form}>

The helpful error message explains a couple possible fixes. I went for the easy one:

<.form
  for={%{}}
  as={:gender_filter}
  phx-change="gender-filter"
  phx-target={@myself}
  id="gender-form"
>

Marked As Solved

SophieDeBenedetto

SophieDeBenedetto

Author of Programming Phoenix LiveView

You are absolutely correct and have already landed on the right update. You’ll find this and other updated code samples in the next Beta release which Bruce and I are currently hard at work on.

Where Next?

Popular Pragmatic Bookshelf topics Top

cro
I am working on the “Your Turn” for chapter one and building out the restart button talked about on page 27. It recommends looking into ...
New
brian-m-ops
#book-python-testing-with-pytest-second-edition Hi. Thanks for writing the book. I am just learning so this might just of been an issue ...
New
curtosis
Running mix deps.get in the sensor_hub directory fails with the following error: ** (Mix) No SSH public keys found in ~/.ssh. An ssh aut...
New
nicoatridge
Hi, I have just acquired Michael Fazio’s “Kotlin and Android Development” to learn about game programming for Android. I have a game in p...
New
digitalbias
Title: Build a Weather Station with Elixir and Nerves: Problem connecting to Postgres with Grafana on (page 64) If you follow the defau...
New
brunogirin
When trying to run tox in parallel as explained on page 151, I got the following error: tox: error: argument -p/–parallel: expected one...
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
dtonhofer
@parrt In the context of Chapter 4.3, the grammar Java.g4, meant to parse Java 6 compilation units, no longer passes ANTLR (currently 4....
New
dachristenson
@mfazio23 Android Studio will not accept anything I do when trying to use the Transformations class, as described on pp. 140-141. Googl...
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

dasdom
No chair. I have a standing desk. This post was split into a dedicated thread from our thread about chairs :slight_smile:
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
AstonJ
This looks like a stunning keycap set :orange_heart: A LEGENDARY KEYBOARD LIVES ON When you bought an Apple Macintosh computer in the e...
New
New
New
AstonJ
Curious what kind of results others are getting, I think actually prefer the 7B model to the 32B model, not only is it faster but the qua...
New
RobertRichards
Hair Salon Games for Girls Fun Girls Hair Saloon game is mainly developed for kids. This game allows users to select virtual avatars to ...
New
PragmaticBookshelf
Use advanced functional programming principles, practical Domain-Driven Design techniques, and production-ready Elixir code to build scal...
New
xiji2646-netizen
Woke up to this today: Claude Code’s complete source code exposed via npm source map. Not a snippet. All 512,000 lines. 1,900 TypeScript ...
New

Sub Categories: