On Drupal 7 and 8 when selecting a file with an invalid file extension using the managed file field, javascript's onchange
event callback Drupal.file.validateExtension()
is called. This callback:
- removes error messages that were possible inserted into the DOM earlier,
- detects a wrong file extension,
- inserts a new error message into the DOM,
- sets the field's value to an empty string and
- stops propagating the event.
On Internet Explorer 11 programmatically resetting the value using this.value = '';
fires the onchange
event again. This time:
- the previous error message is being removed (the user will never know what went wrong),
- the field has no value, so no wrong file extension is being detected and
- the event propagating is not being stopped (other
onchange
callbacks like D8'sDrupal.file.triggerUploadButton
will get fired).
This can be tested using http://jsfiddle.net/lmeurs/2rEzF/ or with Drupal using http://simplytest.me/project/drupal: set permissions for anonymous users to create articles so you can add articles from different browsers (ie. using http://browserstack.com) and test with the image field.
Sidenote: On < IE11 it seems not possible to programmatically reset the field's value.
Possible solution
The best fix I can think of is to immediately exit Drupal.file.validateExtension()
when the field has no value. Use something like:
if (!this.value) return;