Skip to content

Add "Copy form" button to duplicate a form with its fields and options - #2258

Merged
maebeale merged 2 commits into
mainfrom
maebeale/copy-form-button
Aug 19, 2026
Merged

Add "Copy form" button to duplicate a form with its fields and options#2258
maebeale merged 2 commits into
mainfrom
maebeale/copy-form-button

Conversation

@maebeale

@maebeale maebeale commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

🤖 suggested review level: 3 Read 📖 small additive feature — one service, one action, two view links; core risk is what the deep-copy includes/omits

Why

Admins rebuild near-identical forms by hand. A one-click Copy seeds a new editable form (COPY of [Name]) from an existing one so they can tweak rather than start from scratch.

What

  • FormCopyService — transactional deep-copy of a Form.
    • Copies every form_field (order preserved) and each field's form_field_answer_options, re-pointed at the shared AnswerOption records (not duplicated).
    • Leaves slug nil and published false — a published form requires a unique slug.
    • Does not copy submissions, event links, user_forms, or reports.
    • Keeps role — nothing selects a standalone form by role expecting uniqueness (event-level lookups go through event_forms), and role stays editable in the form editor.
  • POST /forms/:id/copyFormsController#copy (admin-gated), redirects to the new form's editor.
  • Copy link on the forms index row and the show-page action bar, each with a confirm.
  • Features & tips seed — new Copy a form entry in config/features.yml.

Tests

  • FormCopyService spec — naming, field/option copy, shared AnswerOption reuse, slug/published reset, submissions/event links excluded, original untouched.
  • POST /forms/:id/copy request spec — admin success + redirect, non-admin denied.

Admins rebuild near-identical forms by hand today. A one-click copy
seeds a new editable form ("COPY of [Name]") from an existing one so
they can tweak rather than start over.

The copy leaves slug nil and published false (a published form requires
a unique slug); event links, submissions, and reports are intentionally
not carried over. AnswerOptions are shared records, so the join rows are
re-pointed at them rather than duplicated.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@maebeale
maebeale marked this pull request as ready for review August 18, 2026 14:44
Surfaces the new copy-form capability on /features so facilitators and
admins can discover it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@maebeale
maebeale requested a review from jmilljr24 August 19, 2026 12:43

@jmilljr24 jmilljr24 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea! Thanks

@maebeale
maebeale merged commit b7a182e into main Aug 19, 2026
3 checks passed
@maebeale
maebeale deleted the maebeale/copy-form-button branch August 19, 2026 13:39
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

Successfully merging this pull request may close these issues.

2 participants