File widget with multiple values may duplicate empty items

Created on 20 April 2022, over 2 years ago
Updated 30 August 2023, over 1 year 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 about 2 hours 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.

Production build 0.71.5 2024