herisson
Grouping nested forms in phoenix liveview
Hi,
I’m currently trying to build a nested dynamic form using Phoenix’s inputs_for function. However, I need these nested “forms” to be grouped by a common attribute, in my case, day_of_week.
I’ve been trying to figure out how to achieve this but haven’t found a solution yet.
For some additional context, here is a simplified version of my schemas:
defmodule Agenova.Availability do
schema "availabilities" do
field :day_of_week, :integer
belongs_to :schedule, Agenova.Schedule
# Virtual fields for the form
field :delete, :boolean, virtual: true
end
end
defmodule Agenova.Schedule do
schema "schedules" do
field :name, :string
has_many :availabilities, Agenova.Availability
end
end
Using the inputs_for function, I get a form like this:
main form
-> availability form 1
-> availability form 2
.
.
.
But my goal is to have the availabilities grouped by day_of_week, like this:
main form
-> day_of_week: 1
---> availability form 1
---> availability form 2
-> day_of_week: 2
---> availability form 3
---> availability form 4
Am I missing something obvious? Are there any tricks to achieve this?
Thank you!
Popular in Questions
Lets say I have map like this fetching from my database
%{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
Other popular topics
Lets say I have map like this fetching from my database
%{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
I would like to know what is the best IDE for elixir development?
New
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!)
This post collects co...
New
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
New
What learn first? Rust or Elixir
Hi Elixir community!
I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










