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!