opensourcecatholic / marriage-booklet

To help Catholic couples plan their wedding mass
4 stars 2 forks source link

dynamically adding form fields #31

Open JohnRDOrazio opened 3 years ago

JohnRDOrazio commented 3 years ago

In PR #24 I included an example of dynamically adding form fields in a project, for the wedding party members.

However, we don't have the WeddingPartyMembers model just yet, so this is really just illustrative. The field names and ids are pretty much invented, and don't get posted to any kind of model.

Once we have our model in place, I'm guessing we should use some erb templating to generate the base row which can then be cloned, kind of like in this example.

JohnRDOrazio commented 2 years ago

Well we now have our model in place, and with PR #99 we also have some dynamic adding / removing of Wedding Party Members.

However we perhaps need to think this through better. Currently, with PR #99 , Wedding Party Members that don't yet exist in a project can be dynamically added or removed from a project. However, already existing Wedding Party Members can't be removed.

Currently, with PR #99, Wedding Party Members are added dynamically be manually templating the HTML structure in the Javascript file, so as to reflect the HTML structure produced by the Rails form builder. Could this manual templating be perhaps automated, using something like the nested form gem? And perhaps this gem would allow to remove already existing Wedding Party Members by marking them for removal.

JohnRDOrazio commented 2 years ago

Perhaps another useful gem, which seems to have better support and has been updated more recently, is the cocoon gem.