Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 292183

Required flag on file forms breaks on validation

$
0
0

Problem/Motivation

A form with a '#type' => 'file' element that is required will always fail. Since there is no #value set (theoretically, there is no value at all) the validation will raise an error.

Steps to reproduce

1) Create a Form class
2) Add

 $form['file_test_upload'] = [
      '#type' => 'file',
      '#title' => t('Upload a file'),
      '#required' => TRUE,
    ];

to your buildForm method
3) Go to the form
4) Add a file to the field and submit it.
5) Notice the form are not able to be submitted because the file field is required.

Proposed resolution

Add a valueCallback on \Drupal\Core\Render\Element\File.

Remaining tasks

Change notice
Manual testing
Review
Commit

User interface changes

API changes

Elements of #type file now have a #value. This means that using $form_state->getValue('some_file_field') will return an array of \Symfony\Component\HttpFoundation\File\UploadedFile objects

Data model changes

Release notes snippet


Viewing all articles
Browse latest Browse all 292183

Trending Articles