#How to use Form nested attributes

1 messages · Page 1 of 1 (latest)

tender meadow
#

Hey Remix community! I'm coming from a ruby on rails background and am wondering how to start using nested form attributes. I have a playlist with many tracks and tracks can belong to many playlists. Using a join table playlist_tracks. What is the preferred method to work with nested form inputs similar to <input name="playlist[track][url] /> When I parse the data in my ActionFunction I'm only seeing one track and not the full list I've submitted. Any help & insights would be much appreciated.

stable patio
#

have you tried formData.getAll("playlist[track][url]"), this should return an array of all the tracks

tender meadow
#

I will try this now. I'd love to have something like this work if possible: formData.getAll("playlist[track]")

#

Ok, yeah that got the url's in an array but I'd like to have access to the [{ name: "track name", url: "https://bucket.com/file.mp3" }, {...}]

stable patio
#

When I moved over to remix I changed how I structure my forms, so in your case If would have two inputs playlist + id, and track + id, and loop over the two arrays and generate an object that has {name: playlist, tracks: tracks } being that they share the same id

#

Hope thats clear*

tender meadow
#

Yeah, was hoping there would be an easier way. But this should work!

#

And for context, I'm allowing for multi file uploads which upload async. I place hidden fields into the form once uploads complete.

stable patio
#

If this is too messy for you their is a library that I used for a while

#

maybe that would solve your problem?

tender meadow
#

Yeah the Array of objects looks like it may work. I'll give it a try. Thanks for the help @stable patio