File ajax upload fails after form is rebuilt

Created on 10 January 2021, about 4 years ago
Updated 7 November 2023, about 1 year ago

Problem/Motivation

Lets say you have a form with an ajax select field and a file field (eg, image field).

When the select field is changed, the form is rebuilt and replaced on the page.

After this ajax process, the files will no longer be uploaded via ajax.

Steps to reproduce

Blank D9 site, entity with an ajax field and a file field.

Add/edit the entity
Add 1 file, you will see the file being uploaded via ajax
Change the select field to trigger ajax response
Add another file to the file field. It will no longer automatically upload via ajax.

Proposed resolution

I'm not yet sure what the 'good' solution is, but i've found that if you remove/comment out the line:45
$(context).find('input[type="file"]').removeOnce('auto-file-upload').off('.autoFileUpload');

in file /core/modules/file/file.js

Then the problem goes away. I just doen't think it is properly being reattached on ajax form event.

Remaining tasks

Find better solution

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Closed: works as designed

Version

11.0 πŸ”₯

Component
AjaxΒ  β†’

Last updated 1 day ago

Created by

πŸ‡¬πŸ‡§United Kingdom adam clarey

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.

  • πŸ‡³πŸ‡ΏNew Zealand quietone

    @Adam Clarey, Thank you for reporting this problem. We rely on issue reports like this one to resolve bugs and improve Drupal core.

    There has been no activity here for 2 years, except for asking for more information about 1 year ago, when the problem was not reproducible.

    Is this issue still a problem?

    If anyone is experiencing this problem on a supported version of Drupal reopen the issue, by setting the status to 'Active', and provide complete steps to reproduce the issue β†’ (starting from "Install Drupal core").

    Since we need more information to move forward with this issue, I am keeping the status at Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

    Thanks!

  • Status changed to Closed: works as designed about 1 year ago
  • πŸ‡³πŸ‡ΏNew Zealand quietone

    As explained in #8, I am closing this issue.

Production build 0.71.5 2024