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 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.

Comments

rymcveigh created an issue. See original summary.

rymcveigh’s picture

Issue summary: View changes
jrockowitz’s picture

Status: Active » Postponed (maintainer needs more info)

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.

rymcveigh’s picture

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.

greggles’s picture

Status: Postponed (maintainer needs more info) » Active

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

stomusic’s picture

Status: Active » Needs review
StatusFileSize
new986 bytes

Need review, it works in my case

selpi’s picture

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).

wiktorb’s picture

Path #6 fixed the problem.

jrockowitz’s picture

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

topplestack’s picture

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.

kalunna’s picture

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, I need to refill ce form.
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.
Why this difference ?

I apply the patch #6 and it's OK for the error "non-scalar value ..." but I still have the ajax message :
" File upload in progress. Uploaded file may be lost.Do you want to continue?"
I don't now where the problem is.

berdir’s picture

Status: Needs review » Needs work

> 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.

primsi’s picture

Status: Needs work » Needs review
StatusFileSize
new863 bytes

Like that ten.

berdir’s picture

Status: Needs review » Reviewed & tested by the community

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-...
jrockowitz’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.