Add allowed file extensions as 'accept' attribute for file uploads to improve UX

Created on 7 February 2019, almost 6 years ago
Updated 25 January 2024, 10 months ago

Problem/Motivation

The input type="file" can have an accept attribute that browsers can use to filter the file browser to the applicable documents. This is currently applied for the image widget.

However, this is a useful attribute for all file inputs.

Proposed resolution

Apply the allowed file extensions as an accept attribute on the input type="file".

Remaining tasks

  1. Write a patch
  2. Review
  3. Commit

User interface changes

The file browser is filtered to the allowed file extensions.

API changes

None.

Data model changes

None.

✨ Feature request
Status

Needs work

Version

11.0 🔥

Component
File system  →

Last updated about 12 hours ago

Created by

🇳🇱Netherlands idebr

Live updates comments and jobs are added and updated live.
  • Usability

    Makes Drupal easier to use. Preferred over UX, D7UX, etc.

  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇩🇪Germany rgpublic Düsseldorf 🇩🇪 🇪🇺

    @alexpott: +1 for 3.: I think it would make much more sense to offer the file extensions that are actually configured for the field. If I don't want allow PNG, these shouldn't show up in the file selector. So, IMHO, the default should be to set the accept attribute to

    implode(" ",$extensions);

    I'm unsure what we do about the mobile device capture though. Is it really necessary to have image/* to achieve that? What about HTML's "capture" attribute? Doesn't it trigger the "capturability" as well? Otherwise it wouldn't be possible to restrict the image file formats AND allow device capture at the same time, right? In any case, I think it should be a separate option then. Perhaps where you can even select the preferred capture attribute (front/back camera). If enabling this option then disables the ability to select allowed extensions, so be it.

Production build 0.71.5 2024