Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question: proper usage of .inputs_for #362

Open
JannikStreek opened this issue Sep 25, 2024 · 4 comments
Open

question: proper usage of .inputs_for #362

JannikStreek opened this issue Sep 25, 2024 · 4 comments
Assignees

Comments

@JannikStreek
Copy link
Member

JannikStreek commented Sep 25, 2024

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
@PragTob
Copy link
Collaborator

PragTob commented Nov 3, 2024

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 😅

@PragTob
Copy link
Collaborator

PragTob commented Nov 3, 2024

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 😅

Most importantly:

  • they talk about sort_param and drop_param - I believe we'll only need to handling for drop_param. We only ever add to the end (iirc) and order doesn't particularly super matter.
  • We need to set on_replace: :delete which 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.

@PragTob
Copy link
Collaborator

PragTob commented Nov 8, 2024

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.

@PragTob
Copy link
Collaborator

PragTob commented Nov 24, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants