question: proper usage of .inputs_for
Further Notes
Please see the documentation at: https://hexdocs.pm/phoenix_live_view/Phoenix.Component.html#inputs_for/1
In the current code in the admin/edit live_view there is a lot of custom code how to delete the labels. I am not sure we are using the best practice here.
See from the docs this example
schema "mailing_lists" do
field :title, :string
embeds_many :emails, EmailNotification, on_replace: :delete do
field :email, :string
field :name, :string
end
end
inputs_for is just as grand of a fun as I remember from Rails, the entire phoenix liveview book doesn't make a single mention of it :sweat_smile:
Alrighty, took some notes around the code and I think it can be done and simplify things - but I'm too tired to do it today :sweat_smile:
Most importantly:
- they talk about
sort_paramanddrop_param- I believe we'll only need to handling fordrop_param. We only ever add to the end (iirc) and order doesn't particularly super matter. - We need to set
on_replace: :deletewhich is its own can of worms - thorough testing, so that nothing gets deleted by accident
that all said, the last times I did this (long time ago in both Phoenix and Rails) it was a constant source of bugs and frustrations. There, I often just ended up handling the data myself at it was easier.
That said, our example is fairly small/simple and relatively close to the one displayed so it may just work and remove some duplication.
I have some stuff up on inputs-for-thinking - gotta fix some test failures but it seems to be working in general. Also, some details to iron out.
Code for this is on #466 but ran into a limitation of ecto with keeping constraints around that is less trivial to fix than I assumed. I'm still working a bit on that in my personal time but need to get back to the ecto team.