Skip to content

Add a file-upload answer type to the form engine - #2136

Open
maebeale wants to merge 2 commits into
mainfrom
maebeale/form-file-upload-answer
Open

Add a file-upload answer type to the form engine#2136
maebeale wants to merge 2 commits into
mainfrom
maebeale/form-file-upload-answer

Conversation

@maebeale

@maebeale maebeale commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

🤖 suggested review level: 5 Inspect 🔬 new answer type wired through the model enum, submission service, validator, and 6 answer-display sites

Closes #2109

What is the goal of this PR and why is this important?

  • The form engine had no way to represent a file upload, so the post-event survey's "upload a photo of one of your creations" question had to be dropped.
  • Adds a file_upload answer_type so form authors can ask for a file (photo, PDF, doc).

How did you approach the change?

  • Reuse, no migration. A file-upload answer stores its blob on the existing polymorphic Asset (FormAnswer has_one :asset, as: :owner) — the same attachment, content-type validation (Asset::ACCEPTED_CONTENT_TYPES), and image/PDF display machinery story ideas use. No schema change.
  • Direct upload. The public form renders a file input wired to the existing file_preview Stimulus controller; JS streams the file to storage and submits a signed blob id as a normal param — so the form stays non-multipart and the existing params/validator flow is unchanged.
  • Persistence. The three near-identical answer-save loops in PublicRegistration were folded into one persist_answer, which attaches the blob for file fields and stores the filename in submitted_answer (so text-only views/exports still read).
  • Display. All six answer-display sites now go through one shared/_form_answer_value partial: file answers show an inline image thumbnail (or a link for non-images) plus a download link; everything else is unchanged.
  • Validation. FormAnswerValidator treats a required file question as present/blank; Asset enforces the content type on attach.

Anything else to add?

  • Consent pairing deferred — the source survey pairs the photo with a "how may we share this" consent; that's a normal select question an author can add alongside, tracked separately.
  • No-JS fallback: without JS the file isn't uploaded (the form is non-multipart by design); the whole form is Turbo/Stimulus-driven already.
  • On a validation error elsewhere, the file input clears (browsers never re-populate file inputs) and must be reselected.

Registrants can now answer a form question by uploading a file (e.g. the
post-event survey's photo-of-a-creation question). File-upload answers store
their blob on the existing polymorphic Asset — the same attachment,
content-type validation, and image/PDF display machinery story ideas use — so
no migration is needed. Direct upload submits a signed blob id as a normal
param, so the form stays non-multipart.

Fixes #2109.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 9, 2026 20:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

…d views

Covers the new answer_type, its Asset-backed attachment, presence/skip
behavior in FormAnswerValidator, blob attachment + filename storage +
content-type rejection in PublicRegistration, and the answer-display
partial's image preview + download link.
Copilot AI review requested due to automatic review settings August 9, 2026 20:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@maebeale
maebeale requested a review from jmilljr24 August 9, 2026 23:58
@maebeale
maebeale marked this pull request as ready for review August 9, 2026 23:58
@maebeale

Copy link
Copy Markdown
Collaborator Author

@jmilljr24 i'm building up to supporting the post-event survey and the daily surveys via callouts. they ask for people to upload a photo of their work, so that's why i'm angling to change our form answers to support uploads.

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.

Form engine: add a file-upload answer type (photo uploads in forms)

2 participants