Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag for JS enhanced file upload #548

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

DavidBiddle
Copy link

@DavidBiddle DavidBiddle commented Mar 4, 2025

The latest version of govuk-frontend (v5.9.0) includes a new JS-enhanced version of the file upload component.

The nunjucks macro has a javascript flag for enabling this:

{{ govukFileUpload({
	id: "file-upload",
	name: "photo",
	label: {
		text: "Upload your photo"
	},
	javascript: true
}) }}

which inserts a div with a class and data attribute around the input element:

<div class="govuk-form-group">
  <label class="govuk-label" for="file-upload-1">
    Upload a file
  </label>
  <div
    class="govuk-drop-zone"
    data-module="govuk-file-upload">
    <input class="govuk-file-upload" id="file-upload-1" name="fileUpload1" type="file">
  </div>
</div>

This PR adds a new javascript flag to the govuk_file_field to accomplish the same thing.

<%= form_builder.govuk_file_field :file,
        id: "file-upload",
	name: "photo",
	label: {
	  text: "Upload your photo"
	},
	javascript: true
%>

Copy link

netlify bot commented Mar 4, 2025

👷 Deploy request for govuk-form-builder pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit a4aaa0a

DavidBiddle added a commit to alphagov/forms-runner that referenced this pull request Mar 4, 2025
Relies on govuk_design_system_formbuilder gem merging this PR: x-govuk/govuk-form-builder#548
DavidBiddle added a commit to alphagov/forms-runner that referenced this pull request Mar 4, 2025
Relies on govuk_design_system_formbuilder gem merging this PR: x-govuk/govuk-form-builder#548
@peteryates
Copy link
Member

peteryates commented Mar 10, 2025

Looks great thank you @DavidBiddle - Looking to get the updated versions out this week. I suspect the builds will fail until rebased as there were problems with Rails 7.0.

I started playing around with this in draft form too before I noticed your PR. Closed mine in favour of yours.

DavidBiddle and others added 2 commits March 10, 2025 13:25
@DavidBiddle DavidBiddle force-pushed the add-file-upload-javascript-flag branch from 2a8579a to a4aaa0a Compare March 10, 2025 13:25
@DavidBiddle
Copy link
Author

@peteryates thanks for the review! Have accepted your suggestion and rebased

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