I would like to bulk edit a list of items. Let’s call them Todos. There is no parent entity, no ‘List’. The todos themselves are regular Ecto schemas and have changesets.
Now I would like to render one form, with all todos in there, using the regular Phoenix HTML helpers. So that, upon submitting, all changesets can be checked and if any - or multiple - items contain errors, the form is presented to the user again, with the necessary error messages on the erroneous fields.
I can not seem to find a way to generate a ‘parent’ changeset to pass to the form to make this happen. After submit, I can loop the lists of items and validate each one individually. But I need one ‘main’ changeset to pass to the form.
Any ideas? I can do it all manually but that would be a pitty. Thanks!
He doesn’t have a parent record. He’s not managing an embedded association either. He wants to mass edit stand-alone records in the same form.
I remember a RailsCasts episode on doing the same thing in Rails. Maybe it can prove inspirational?
Just shooting off ideas, but you might have loop over the todo items and create a changeset for each, then manually use those changesets in the form. I suspect the form itself would not be backed by a changeset. You could simply post it using @conn.
Perhaps someone with more experience than me can chime in.
I do this pretty often, I just display the form as a row in a table with the overall form wrapping the entire table and each row being indexed by some unique identifier (just adding [#{blah.id}] to the row) then just compare the changes to the original information on submission and build a list of changes to apply (I have a helper function on my repo module to do that).
A lot of them are very situationally specific, and the overall code is awfully tiny to wrap an entire library around… Like my comparison thing has knowledge about my removed_at timestamp fields (never delete or change anything, a new entry with the old entry with a removed_at date added is done instead, which is very much not helpful for most projects). ^.^;