krystofrezac

krystofrezac

Programming Phoenix LiveView: age group filter form (page 222)

The book uses this code in the age group filter:

<form phx-change="age_group_filter" phx-target="<%= @myself%>">
        <label>Filter by age group:</label>
        <select name="age_group_filter" id="age_group_filter">
          <%= for age_group <-
                ["all", "18 and under", "18 to 25", "25 to 35", "35 and up"] do %>
            <option
              value="<%= age_group %>"
              <%=if @age_group_filter == age_group, do: "selected" %> >
                <%=age_group%>
            </option>
          <% end %>
        </select>
      </form>

But I think that there is a more elegant way to do this:

<%= f = form_for :age_group, "#", [phx_change: :age_group_change, phx_target: @myself] %>
    <%= select f, :age_group_filter,
        ["all", "18 and under", "18 to 25", "25 to 35", "35 and up"],
        selected: @age_group_filter
    %>
</form>
0 689 1

First Post!

almirsarajcic

almirsarajcic

Agreed.

Maybe this could be added below the current version to show a more elegant solution using Phoenix.HTML helper.

Popular Pragmatic Bookshelf topics Top

New
iPaul
page 37 ANTLRInputStream input = new ANTLRInputStream(is); as of ANTLR 4 .8 should be: CharStream stream = CharStreams.fromStream(i...
4 983 0
New
raul
Hi Travis! Thank you for the cool book! :slight_smile: I made a list of issues and thought I could post them chapter by chapter. I’m rev...
2 1179 3
New
herminiotorres
Hi! I know not the intentions behind this narrative when called, on page XI: mount() |&gt; handle_event() |&gt; render() but the correc...
3 1296 17
New
New
jskubick
I’m under the impression that when the reader gets to page 136 (“View Data with the Database Inspector”), the code SHOULD be able to buil...
2 1164 8
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...
0 1103 1
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 ...
6 1110 5
New
EdBorn
Title: Agile Web Development with Rails 7: (page 70) I am running windows 11 pro with rails 7.0.3 and ruby 3.1.2p20 (2022-04-12 revision...
0 1127 1
New
ggerico
I got this error when executing the plot files on macOS Ventura 13.0.1 with Python 3.10.8 and matplotlib 3.6.1: programming_ML/code/03_...
1 3033 5
New

Other popular topics Top

ohm
Which, if any, games do you play? On what platform? I just bought (and completed) Minecraft Dungeons for my Nintendo Switch. Other than ...
245 5132 101
New
dasdom
No chair. I have a standing desk. This post was split into a dedicated thread from our thread about chairs :slight_smile:
177 8457 77
New
Exadra37
I am a Linux user since 2012, more or less, and I always use Ubuntu on my computers, and my last 2 laptops have been used Thinkpads, wher...
64 2959 29
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...
14 5831 7
New
Exadra37
Oh just spent so much time on this to discover now that RancherOS is in end of life but Rancher is refusing to mark the Github repo as su...
10 4985 6
New
AstonJ
If you are experiencing Rails console using 100% CPU on your dev machine, then updating your development and test gems might fix the issu...
3 3482 3
New
PragmaticBookshelf
“A Mystical Experience” Hero’s Journey with Paolo Perrotta @nusco Ever wonder how authoring books compares to writing articles?...
31 3392 15
New
PragmaticBookshelf
Author Spotlight Jamis Buck @jamis This month, we have the pleasure of spotlighting author Jamis Buck, who has written Mazes for Prog...
21 5418 9
New
New
AstonJ
This is a very quick guide, you just need to: Download LM Studio: https://lmstudio.ai/ Click on search Type DeepSeek, then select the o...
13 3588 10
New

Latest in PragProg Customers

View all threads ❯