Feature: attachment input - #60
Merged
Merged
Conversation
sfnelson
marked this pull request as draft
July 23, 2026 04:51
sfnelson
force-pushed
the
feature/attachment-input
branch
6 times, most recently
from
July 28, 2026 23:56
033d057 to
f774554
Compare
sfnelson
force-pushed
the
feature/attachment-input
branch
4 times, most recently
from
July 31, 2026 13:13
5a3b5a8 to
17ec2e9
Compare
sfnelson
marked this pull request as ready for review
July 31, 2026 13:13
sfnelson
force-pushed
the
feature/attachment-input
branch
from
July 31, 2026 13:49
17ec2e9 to
b035fe9
Compare
Reduces the noise when listening to a form. Consistent with GOVUK.
sfnelson
force-pushed
the
feature/attachment-input
branch
from
August 2, 2026 11:27
b035fe9 to
204cd1e
Compare
sfnelson
force-pushed
the
feature/attachment-input
branch
from
August 3, 2026 03:01
204cd1e to
68e966e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Upgrade notes (1.x → 2.0)
This release replaces the image/document file fields with an ActiveStorage-backed
attachment field: preview figures, drag-and-drop, async direct uploads with retry,
removal, and a complete no-JavaScript fallback.
govuk_image_fieldandgovuk_document_fieldkeep their names and render the new field by default.Required changes
Attachment values must be ActiveStorage.
govuk_image_field/govuk_document_fieldnow require ahas_one_attached/has_many_attachedattribute and raise
ArgumentErrorotherwise (previously they rendered a plainenhanced input for e.g. form objects). For plain file uploads, switch to
govuk_file_field.Required attachments need a presence validation. Removal is always offered —
the
optional:argument no longer does anything. A required attachment isguarded by its model validation, not by the UI hiding removal.
Wire the JavaScript with
GOVUK.start. The attachment and file-uploadenhancements are Stimulus-powered. Register the gem on your Stimulus application
from your bundle — this replaces the 1.x
application.load(govuk)extensionwiring, which now raises a
TypeErrorat boot (the default export is no longerthe controller definitions array):
startregisters the controllers and keeps the page enhanced for the wholesession, including across Turbo visits. If you're not running Stimulus, or you
want the GOV.UK enhancements kept separate from your application, render
<%= govuk_formbuilder_init %>at the end of<body>instead — it enhancesper page render, registering the controllers on a gem-owned Stimulus
application. Without either wiring, attachment fields fail open to a native
file input — functional, but no previews, drag-and-drop, or direct uploads.
Delete Turbo re-init wiring. Enhancement now observes the DOM: lazy frames,
stream inserts, and morphs re-enhance automatically. Remove any
turbo:render/turbo:frame-loadre-initialisation listeners (theturbo:rendervariant neverworked); repeat calls are harmless no-ops.
Behaviour changes to review
and the Rails i18n vocabulary (
katalyst.govuk.attachment.*) are now read by theJavaScript. Previously the documented text options rendered but were never read,
so announcements were always English — review any strings you set.
discarded drops outside
mime_types; nowacceptremains a picker courtesy andthe server's validations are the authority. Add model validations if you relied
on the client filter.
data-*wiring arealways
govuk-*— previously a non-default brand rendered controller names theJS never matched, so those controllers never connected. The gem's compiled CSS
stays govuk-prefixed; a custom brand presumes a consumer-supplied frontend build.
label:,caption:,hint:, andform_group:on image/document fields are nowforwarded (previously captured and silently dropped).
GOVUKDesignSystemFormBuilder.config.attachment_preview_representation(default:
resize_to_fill: [256, 256]— a crisp centre-cropped square, sizedwith leeway for dense displays). The square preview box is filled with
object-fit: cover; a consumer wanting whole-imagecontainpreviewsoverrides the representation too.
JavaScript dependencies
The module imports
@hotwired/stimulusand@rails/activestorage. Importmap appsget the gem's pins automatically; jsbundling apps must provide both packages at
runtime — the wiring is the same
GOVUK.start(application), from your own bundle.Transitional escape hatch
The legacy field implementations remain in the gem behind a flag, to stage a
migration — the flag and the legacy code will be removed together in a future
release: