File input value contains a non-scalar value

Created on 23 January 2023, over 1 year ago
Updated 10 June 2023, about 1 year ago

Problem/Motivation

On Drupal Version 10, backward navigation no longer works when adding a file input to a Wizard form that uses Ajax. Something seems to be hijacking the JS click event preventing the page navigation submit input from getting triggered when a user clicks the title in the progress bar.

When I try to trigger the navigation with JS (using the browser console) it also errors, but it works if I display the progress bar submit actions and click the button myself.

Steps to reproduce

On Drupal 10:

  • Enable the webform_examples module
  • Add a file field to the second page of the example_wizard form
  • Submit the first page of the form
  • Before adding a file, try navigating to the first page using the progress bar
  • If a file has not been uploaded then you should see a console error indicating that the ajax call returned a 400 response code with the error message "Input value '{input_name}' contains a non-scalar value."

I've attached the config for an adapted example_wizard form with a file input to this issue.

Proposed resolution

The non-scaler error is generated by the symphony InputBag class. The $value that is being posted for the file input seems to be an array rather than NULL.

A similar issue occurred in the Views Reference Field module here 🐛 Ajax pager - Input value "viewsreference" contains a non-scalar value Fixed but I'm not entirely convinced this is the same issue because the form submits when I manually click the progress submit button.

Being that the submit works when a user manually clicks the button makes me think that it is a different JS file hijacking the click event. I tried debugging the webform.element.managed_file.js file and the webform.ajax.js file with no success.

I also tested to see if this is a core AJAX issue by creating a vanilla form with a file input and an ajax submit button, but the ajax click event worked there, indicating that it has to do with the webform module itself.

🐛 Bug report
Status

Fixed

Version

6.2

Component

Code

Created by

🇺🇸United States rymcveigh

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @rymcveigh
  • Status changed to Postponed: needs info over 1 year ago
  • 🇺🇸United States jrockowitz Brooklyn, NY

    I am willing to make a small bet this regression is being triggered by 🐛 [Drupal 9.2.x] Replace jquery.removeOnce with new once API Fixed .

  • 🇺🇸United States rymcveigh

    I am willing to make a small bet this regression is being triggered by #3335861: [Drupal 9.2.x] Replace jquery.removeOnce with new once API.

    It actually happens on the current 6.2@beta release of webform as well as the 6.2.x branch. So I do not think they are related.

    I am able to reproduce this issue using Drupal 10 with PHP 8.1 using the composer installed 6.2@beta version on the module (that doesn't have the removeOnce adjustment). But, the removeOnce function doesn't work on D10 anyway so... I gues it could be a regression... 🤷

    In any case, the current version of dev works okay on Drupal 9.5. This bug seems to be related to a change in core.

  • Status changed to Active over 1 year ago
  • 🇺🇸United States greggles Denver, Colorado, USA

    Setting back to active based on the research and feedback in #4.

  • Status changed to Needs review about 1 year ago
  • 🇺🇦Ukraine stomusic Ukraine

    Need review, it works in my case

  • 🇷🇺Russia Selpi

    Thanks a lot, patch in #6 fixed the problem with file/image upload element. Without it placing file/image upload element to a form page with another element that allows to add more rows for example was breaking the form (adding was not working with ajax error).

  • 🇵🇱Poland wiktorb

    Path #6 fixed problem.

  • 🇺🇸United States jrockowitz Brooklyn, NY

    Using Drupal::request()->request->all('files') returns all form values and triggers the code for every request. The root cause needs to be diagnosed.

  • 🇺🇸United States Topplestack Rural, Idaho

    I'm getting the same error message after uploading an image and then trying to remove selected image. #6 does not resolve the issue. Could be separate issue, but based on the current information, they appear to be related.

  • I get the same error (recorded in the logs) when I select my file which loads then I click on "submit" then, it displays this message:
    " File upload in progress. Uploaded file may be lost.Do you want to continue?"
    If I click "Continue", then my form is "reset" I can't load a file
    On the other hand, when I use the TEST option of the form, I no longer have an error displayed and the test file is load.

  • Status changed to Needs work about 1 year ago
  • 🇨🇭Switzerland Berdir Switzerland

    > Using Drupal::request()->request->all('files') returns all form values and triggers the code for every request. The root cause needs to be diagnosed.

    I think there's not much to be diagnosed.

    Symfony 5/6 deprecated/removed the ability to return non-scalar values, you need to use all() for that. No way around that.

    However, the patch is wrong, all() has no argument, intead you need to check the return value for the array key files.

  • Status changed to Needs review about 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 8
    last update about 1 year ago
    534 pass
  • 🇸🇮Slovenia Primsi

    Like that ten.

  • Status changed to RTBC about 1 year ago
  • 🇨🇭Switzerland Berdir Switzerland

    Yeah, confirmed to work on our project.

    Could also be inlined into the !empty() or the other check could also use $request_params then, but this works.

    • Primsi authored 6fdb1958 on 6.1.x
      Issue #3335962 by stomusic, Primsi: File input value contains a non-...
    • Primsi authored 6fdb1958 on 6.x
      Issue #3335962 by stomusic, Primsi: File input value contains a non-...
    • Primsi authored 6fdb1958 on 6.2.x
      Issue #3335962 by stomusic, Primsi: File input value contains a non-...
  • Status changed to Fixed about 1 year ago
  • 🇺🇸United States jrockowitz Brooklyn, NY
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024