Programming Phoenix LiveView B9.0: Form code syntax does not work as written (p. 198)

This is an identical issue to the one I described in in this thread.

On page 198, the survey form LiveComponent is described using a syntax that appears to no longer work. The workaround is simple, but as mentioned in the other thread, the live view code may need to be revamped to work with current LiveView best practices.

To implement the easy workaround, modify the field attribute in the following file to use the syntax shown in the current LiveView docs.

lib/pento_web/live/demographic_live/form.html.heex

Change this:

<.input
  field={{f, :gender}}
  type="select"
  label="Gender"
  options={Pento.Survey.Demographic.gender_options()}
/>
<.input
  field={{f, :year_of_birth}}
  type="select"
  label="Year of birth"
  options={Enum.reverse(1900..2023)}
/>

To this:

<.input
  field={f[:gender]}
  type="select"
  label="Gender"
  options={Pento.Survey.Demographic.gender_options()}
/>
<.input
  field={f[:year_of_birth]}
  type="select"
  label="Year of birth"
  options={Enum.reverse(1900..2023)}
/>

Bonus error: The options for the year_of_birth select field on page 199 (1920..2023) do not match the options described in the Demographic’s core logic on page 166 (1900..2022).

Thanks for sharing this. We’re working on a new version of the Beta book right now and it will be out in a few weeks. This and all other forms will be updated.