jaimeiniesta
What is the proper way to interpolate boolean attributes like checked in an input in the new HEEx engine?
For example, in LEEx if I wanted to include it based on some condition, I would do this:
<input type="checkbox" name="web_pages[]" value="<%= w.id %>" <%= if w.id in @selected, do: "checked" %> />
Which would generate HTML like this:
<input type="checkbox" name="web_pages[]" value="1" />
<input type="checkbox" name="web_pages[]" value="2" checked />
Now in HEEx I do this
<input type="checkbox" name="web_pages[]" value={w.id} checked={if w.id in @selected, do: "true", else: nil} />
Which also works, if a nil value is passed then the checked attribute won’t be passed at all, but if I pass true then it will generate this:
<input type="checkbox" name="web_pages[]" value="2" checked="true" />
Which is correct, but longer and a bit uglier. I would have expected that this would work:
<input type="checkbox" name="web_pages[]" value={w.id} {if w.id in @selected, do: "checked"} />
But it doesn’t, it fails with protocol Enumerable not implemented for nil of type Atom. It looks like interpolation must always be bound to an attribute name in the HTML tag, right?
Trending in Questions
One of my LiveView view’s has a very heavy javascript dependency so I want to avoid loading it for every page on the site, while still us...
New
Hi all!
I know that quite a few people use Phoenix LiveView but it is hard to get a more up-to-date list of folks/companies using it. I ...
New
I load tested a plain Phoenix chat app backed by Postgres with 100 million messages in it, everything on default settings, to see what br...
New
Hey, I know this has been discussed ad nauseum, but I couldn’t find a definitive answer or at least some consensus around this, so let me...
New
I don’t suppose you can lazy load a library depending on runtime data? For example if it’s a certain user they can lazy load ‘library A’ ...
New
Hey everyone, I have been building a lightweight Phoenix backend aimed at backing up and synchronizing user profiles across mobile device...
New
Other Trending Topics
Hello everyone!
I’m curious - do you run your apps on a plain VPS, a PaaS (like Fly, Gigalixir, Render, etc.) or a VPS with a deploy too...
New
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
On November 23, 2026, an unauthorized third party exploited a vulnerability in hex.pm (CVE-2026-129514, CVSS 10.0) that let them run comm...
New
Hi everyone :waving_hand:
I’ve been working on PhiaUI, an open-source UI component library for Phoenix LiveView, and I wanted to share i...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #code-sync
- #exunit
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #ai
- #authentication
- #elixirconf-us
- #umbrella
- #full-time-contract
- #blog-post
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-eu
- #distillery
- #security
- #processes
- #api
- #forms
- #hex











Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Qqwy
It is OK to assign to multiple dynamic attributes at once, using the syntax of your last example.
However, the result is expected to be a keyword-list or a map. Currently you are returning a single string.
Instead, you can do, for instance:
However, in neither case will the result be a valueless attribute.
I don’t think this is a bad thing. Instead, not supporting this special case makes it easier for the HEEx parser to always generate correct HTML.
LostKobrakai
<input type="checkbox" checked={@boolean}>should just work.jaimeiniesta
Makes sense, I would prefer to be able to generate valueless attributes like
checkedinstead ofchecked=truebut it’s not that important, just checking if there was a way to do that.Thanks!
LostKobrakai
I’ve no heex project at hand to check, but I’m quite confident it just generates a valueless attribute or no attribute.
jaimeiniesta
Ah! It does! The following works as expected, generating a valueless attribute for
trueor no attribute forfalse.Awesome, thanks!
crockwave
Here is a
Surfacereference onboolean attributes. Is there corresponding documentation in Phoenix Liveview on this subject that we can reference?Surface (surface-ui.org)