Phoenix.HTML select/4

Hi, just wondering if this version of select/4 works as described in the documentation:

options are expected to be an enumerable which will be used to generate each respective option. The enumerable may have:

keyword lists - each keyword list is expected to have the keys :value and :label. Additional keys such as :disabled may be given to customize the option

When I try to run:

select(form, :role, [[key: "Admin", value: "admin", disabled: true],
                 [key: "User", value: "user"]])

I get:

(ArgumentError) lists in Phoenix.HTML and templates may only contain integers representing bytes, binaries or other lists, got invalid entry

I’m also confused whether I need to use β€œkey” or β€œlabel” as the key in the keyword list. I think I’ve tried every conceivable permutation of strings and atoms all to no avail.

My goal is to add a class on to each option. Thanks.

Hmm, your example worked here when copy/pasted in. Maybe your form is corrupt. Just as a test can you replace the form argument with the atom :form instead and see if you don’t get an error? If no error then something is wrong with the form, in which case a minimal example that we can copy/paste in to IEX would help to diagnose further. :slight_smile:

How strange! I’ve just popped the select code from the documentation into an existing working form that uses a select of the 2nd type (two-item tuples). Same error, so I’m not sure I can blame the form :slight_smile: I’ve tried switching to an atom with the same result.

** (ArgumentError) lists in Phoenix.HTML and templates may only contain integers representing bytes, binaries or other lists, got invalid entry: {:key, "Admin"}

What version of Phoenix, Phoenix.HTML, and etc. are you running? I’m running current stable on all.

Specifically, what is your mix.lock file contents?

Phoenix is at 1.3.0
Phoenix.HTML looks like 2.9.3. I’m not sure how to check to be honest :slight_smile:
I can see that Phoenix.HTML looks to be at 2.10.5 in the documentation - how do I bump if that’s worth trying?
mix deps.update phoenix_html

{:phoenix_html, β€œ~> 2.9”, [hex: :phoenix_html, optional: true]}, {:plug, β€œ~> 1.0”, [hex: :plug, optional: false]}]},
β€œphoenix_html”: {:hex, :phoenix_html, β€œ2.9.3”, β€œ1b5a2122cbf743aa242f54dced8a4f1cc778b8bd304f4b4c0043a6250c58e258”, [:mix], [{:plug, β€œ~> 1.0”, [hex: :plug, optional: false]}]},

Here are the mix file deps

defp deps do
[{:phoenix, β€œ~> 1.3.0”},
{:phoenix_pubsub, β€œ~> 1.0”},
{:phoenix_ecto, β€œ~> 3.0”},
{:postgrex, β€œ>= 0.0.0”},
{:phoenix_html, β€œ~> 2.6”},
{:phoenix_live_reload, β€œ~> 1.0”, only: :dev},
{:gettext, β€œ~> 0.11”},
{:cowboy, β€œ~> 1.0”},
{:httpoison, β€œ~> 0.8”},
{:httpotion, β€œ~> 3.0.2”},
{:sweet_xml, β€œ~> 0.6”},
{:floki, β€œ~> 0.17.0”},
{:erlsom, git: β€œgit@github.com:willemdj/erlsom.git”},
{:plug, β€œ~> 1.0”}
]
end

1 Like

Fixed :smile: It was running on an older version of Phoenix.HTML
Thanks @OvermindDL1

1 Like