kuzyn
I am trying to create a LiveView form that allows 6 checkboxs to be toggled and saved as a single array of boolean values under Ecto.
The problem is that every time I change the form by clicking on the checkboxes, this array grows and new empty fields are added to the LV. As far as I can tell, it looks like it is appending a value before the validate handle_event. I cannot figure out why (I have another field, {:array. :float} that works just fine in the same view. Otherwise, i have nothing but boilerplate in my live component file (nothing added to mount, update, etc)…
What the bug looks like:

In my context:
defmodule AppName.Things.MyThing do
use Ecto.Schema
import Ecto.Changeset
schema "things" do
field :my_list, {:array, :boolean}, default: [false, false, false, false, false, false]
timestamps(type: :utc_datetime)
end
@doc false
def changeset(my_thing, attrs) do
my_thing
|> cast(attrs, [
:included
])
end
end
In my LV:
@impl true
def render(assigns) do
~H"""
<div>
<.simple_form
for={@form}
id="my_thing-form"
phx-target={@myself}
phx-change="validate"
phx-submit="save"
>
<.input
:for={
{entry, index} <-
Enum.with_index(Ecto.Changeset.get_field(@form.source, :my_list, []))
}
value={entry}
name="my_thing[my_list][]"
type="checkbox"
/>
<:actions>
<.button phx-disable-with="Saving...">Save My Thing</.button>
</:actions>
</.simple_form>
</div>
"""
end
Is this a problem from using :for on the checkbox input? I have tried a few things but they all felt hacky and did not work.
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m aware of 2 such projects, are there others?
git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
Hi all,
I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
Hi,
we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
Hi all, I’m new here and would like to hear peoples views on my Elixir/Phoenix based game-engine! :smiley:
Mutonex gamedesign was finish...
New
Hello
I’ve been coding in Elixir for almost two years now because of my current job where we implemented Elixir in our application. But ...
New
Hi, I’m evaluating Ash as a foundation for our future business applications.
So far I love it, and there’s just one usecase I haven’t be...
New
Other Trending Topics
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
Hi everyone :waving_hand:
I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
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
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
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
- #exunit
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #elixirconf-us
- #blog-post
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #hex











Showing Posts 1 to 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
frankdugan3
This fly.io blog covers how to do it pretty well. Can vouch for it: I’ve based my checkbox group components on it.
kuzyn
Thanks Frank! My mistake was definitely not looking more into the limitations of the checkbox input in the
core_component. See How to make checkbox work with form bindings Phoenix LV? - #2 by LostKobrakai.For future reference, this thread is also related: How to wire up a Phoenix form for a field {:array, :string}?
What I ended up with is an ugly ass solution that works:
:check_optionsassign initiated with existingmy_listvalues (if present)<input type="checkbox" ...>inside of a:fordivphx-changehandler to handle the checkboxes on/off and sanitize them into my temporarychecked_optionsin my assignMap.mergein mysavehandler that take thischecked_optionsand put it into my params prior to generating the changesetSo in other words, I am binding the data manually with handlers and making sure it is merged into the params/changeset rather than relying on the
field={@form[:my_list]}convenience. A whole lot uglier but at least I can move on