herisson

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!


Where Next?

Popular in Questions Top

hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
lessless
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
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
stefanchrobot
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
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
gshaw
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
romenigld
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 Top

hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
axelson
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...
239 49266 226
New
gausby
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...
1207 40165 209
New
AngeloChecked
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
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New

We're in Beta

About us Mission Statement