Hello
I've found bug in validation of the file extension.
How to reproduce:
- Create some content type with file upload field. This field should allow more than one value.
- Open node create form
- Try to upload file with not allowed extension, for example .xls - you will see JS validation error. All fine.
- Upload file with allowed extension. For example .txt - It will uploaded. All fine.
- 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.