- last update
about 1 year ago 2,161 pass
If you choose file, upload it and remove, choose another file again ( with invalid extension), then error message about extension is shown and hidden immediately. Bug may be in modules/file/file.js in validateExtension function:
validateExtension: function (event) {
// Remove any previous errors.
$('.file-upload-js-error').remove(); // !!!! PROBLEM HERE - this function is called twice, second time with this.value == ''
// Add client side validation for the input[type=file].
var extensionPattern = event.data.extensions.replace(/,\s*/g, '|');
if (extensionPattern.length > 1 && this.value.length > 0) {
var acceptableMatch = new RegExp('\\.(' + extensionPattern + ')$', 'gi');
if (!acceptableMatch.test(this.value)) {
var error = Drupal.t("The selected file %filename cannot be uploaded. Only files with the following extensions are allowed: %extensions.", {
'%filename': this.value,
'%extensions': extensionPattern.replace(/\|/g, ', ')
});
$(this).parents('div.form-managed-file').prepend('<div class="messages error file-upload-js-error">' + error + '</div>');
this.value = '';
return false;
}
}
},
Temporarily I override this function in my custom js-file with this code:
Drupal.file.validateExtension = function (event) {
// Remove any previous errors.
if (this.value) // THIS CONDITION was added
{
$('.file-upload-js-error').remove();
// Add client side validation for the input[type=file].
var extensionPattern = event.data.extensions.replace(/,\s*/g, '|');
if (extensionPattern.length > 1 && this.value.length > 0) {
var acceptableMatch = new RegExp('\\.(' + extensionPattern + ')$', 'gi');
if (!acceptableMatch.test(this.value)) {
var error = Drupal.t("The selected file %filename cannot be uploaded. Only files with the following extensions are allowed: %extensions.", {
'%filename': this.value,
'%extensions': extensionPattern.replace(/\|/g, ', ')
});
$(this).parents('div.form-managed-file').prepend('<div class="messages error file-upload-js-error">' + error + '</div>');
this.value = '';
return false;
}
}
}
}
Needs review
7.0 ⚰️
The change/bugfix cannot be fully demonstrated by automated testing, and thus requires manual testing in a variety of environments.
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.