Validation of file extension doesn't work on JS side

Created on 15 October 2015, about 9 years ago
Updated 18 October 2023, about 1 year ago

Hello

I've found bug in validation of the file extension.

How to reproduce:

  1. Create some content type with file upload field. This field should allow more than one value.
  2. Open node create form
  3. Try to upload file with not allowed extension, for example .xls - you will see JS validation error. All fine.
  4. Upload file with allowed extension. For example .txt - It will uploaded. All fine.
  5. Try to upload file with not allowed extension again, as the second item of this field. You'll not see JS validation error and file wouldn't be uploaded. It's wrong. You should see JS validation error.

How is it happens:
When you upload the first file, you get the JS commands from server. They're two insert commands.
The first insert command uses method "prepend" and executes "attachBehaviors"
The second insert command uses method "replaceWith" and executes "detachBehaviors" and next the "attachBehaviors" again.

After execution of these commands the "Behaviors" will be attached one more time in this code (ajax.js)

  if (this.form) {
    var settings = this.settings || Drupal.settings;
    Drupal.attachBehaviors(this.form, settings);
  }

So, the behaviors have been attached twice on the file upload element.
And function validateExtension (file.js) will be called twice.

So, the behaviors have been attached twice on the file upload element.
And function validateExtension (file.js) will be called twice.

First execution:
If uploaded file is invalid, this function will add error text and remove value from file upload field.
Second execution:
Function removes error text via this code (each time):
$('.file-upload-js-error').remove();
and error text cannot be added again, because value is empty.
So, the error text is not displayed.

It happens very fast and for user it looks like he tries to upload file but it cannot uploaded and nothing happens.

P.S. I've checked this problem for D7 and D8. It happens only for D7.

πŸ› Bug report
Status

Closed: duplicate

Version

7.0 ⚰️

Component
File systemΒ  β†’

Last updated about 11 hours ago

Created by

πŸ‡·πŸ‡ΊRussia eugene.ilyin

Live updates comments and jobs are added and updated live.
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.

Production build 0.71.5 2024