Skip to content

Make file input selector more specific when setting up JavaScript-enhanced file input#7268

Open
peteryates wants to merge 1 commit into
alphagov:mainfrom
x-govuk:make-file-input-query-selector-more-specific
Open

Make file input selector more specific when setting up JavaScript-enhanced file input#7268
peteryates wants to merge 1 commit into
alphagov:mainfrom
x-govuk:make-file-input-query-selector-more-specific

Conversation

@peteryates

Copy link
Copy Markdown
Contributor

Now, instead of finding any input and failing if its type isn't "file", it finds inputs with type "file" and fails if nothing is found.

Since version 7.0, when the multiple attribute is set on a file input, Rails also renders a hidden input just before the file input, e.g.,

<input name="profile[profile_photo][]" type="hidden" value="">
<input id="profile-profile-photo-field" class="govuk-file-upload" multiple="multiple" type="file" name="profile[profile_photo][]">

This ensures that when the user submits a form with no files selected, the form submission includes profile[profile_photo][], and Rails can delete any files that are attached.

Now, instead of finding any input and failing if its type isn't "file",
it finds inputs with type "file" and fails if nothing is found.

Since version 7.0, when the multiple attribute is set on a file input,
Rails also renders a hidden input just before the file input, e.g.,

<input name="profile[profile_photo][]" type="hidden" value="">
<input id="profile-profile-photo-field" class="govuk-file-upload" multiple="multiple" type="file" name="profile[profile_photo][]">

This ensures that when the user submits a form with no files selected,
the form submission includes profile[profile_photo][], and Rails can
delete any files that are attached.
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.

1 participant