Problem/Motivation

It seems the required attribute does nothing on file inputs.
This could be a problem for #2847425: #states not affecting visibility/requirement of managed_file and #2938441: managed_file HTML5 required validation , these issues will add new ways to have this attribute on input fields so it needs to do something.

This seems to happen because disableFields() in file.js disables every input field when submitting the form, so the required attribute is not triggered by the browser.
I suppose there is a good reason to do this but it could probably be improved.

Steps to reproduce

Override the input--file.html.twig template to add the required attribute on file inputs.
Add a file field on a node bundle.
Browse to the create form for this bundle.
Leave the file field empty and click on Save: the browser does not prevent submitting the form.

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Comments

prudloff created an issue. See original summary.

prudloff’s picture

Issue summary: View changes
kim.pepper’s picture

I know there is an existing issue about this somewhere but I can't find it.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.