File widget with multiple values may duplicate empty items

Created on 20 April 2022, about 2 years ago
Updated 30 August 2023, 10 months ago

Problem/Motivation

File field widget with multiple values could erroneously create multiple empty items under special circumstances. For example, within a multi-step form that excludes the file field on the initial step using the #access render property.

Steps to reproduce

Quick and easy multi-step node form simulation:

  1. Create a content type with a file field and unlimited cardinality.
  2. Alter the node form to rebuild on submit.
  3. Hide file field widget with ['#access' => FALSE] on the element.
  4. Open the node form.
  5. Remove #access property from the file field widget element.
  6. Click submit to rebuild node form.
  7. Observe the duplicated empty item (compare with screenshot).

Proposed resolution

Do not create elements for empty items. Empty elements are created after existing items are processed.

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
File systemΒ  β†’

Last updated 4 minutes ago

Created by

πŸ‡ΊπŸ‡ΈUnited States robphillips

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request β†’ as a guide.

    This will need a test case to show the issue.

    Did not test patch.

  • πŸ‡ΊπŸ‡ΈUnited States jimmynash

    Just chiming in. This patch fixes an issue I was experiencing with Entity Form Steps β†’ where unlimited file fields were displaying strangely exactly as the attached screenshot.

    Unfortunately I don't have the skill to write a test for this as of yet to contribute.

Production build 0.69.0 2024