Issue with Drupal file upload field if form is replaced with AJAX

Posted by edsardachuk - September 19, 2025

fileAutoUpload core js-once behavior detaches if the form is replaced with AJAX, resulting in new file uploads not triggering file preview loads. I had to investigate it and find a temporary hot fix.

Drupal.behaviors.addToCartFileAutoUploadFix = {
    attach(context) {
      // Behaviour from Drupal Core doesn't work when form is replaced with AJAX.
      $(once('addToCartFileAutoUploadFix', 'input[type="file"]', context)).each(function () {
        $(this).on(
          'change.autoFileUploadFix',
          Drupal.file.triggerUploadButton,
        );
      });
    }
  };