I’m building a form for inputting people’s travel plans, and as part of that, I need to capture who will be in what country on what days (see diagram for relevant section of the form)
Next to the Add Another Item button to allow me to add another top-level itinerary, I would like to add a ‘duplicate last itinerary button’ that would add another item to the itinerary list, but copy the contents of the last itinerary item into it. Ideally, the button would only copy the data in the section surrounded by a dotted line on the diagram (the itinerary leg content) and leave the traveler(s) field blank.
If there is a ready module to do this, that would be fantastic, but I’d be perfectly happy for a code-based solution or failing that, pointers to good info.
I’ve found How to pre-populate multiple "field collection" fields in node form which in spite of being closed seems like it may contain good information on populating the entries. I think I need to know how to do basically 3 things and what hooks make sense to accomplish them:
- add a button alongside the other multi-entry field buttons
- read the contents of the last itinerary leg field collection field in the list of itineraries.
- add a new item, and populate the itinerary leg field collection fields with the values from step 2.