Problem/Motivation

This functionality does not work correctly for paragraphs in "Closed" edit mode.

Steps to reproduce

  • Create a basic_page content type with a multivalue field (test_field_node) referencing a paragraph type (test_paragraph).
  • Ensure that test_paragraph contains a multivalue (unlimited) field (test_paragraph_field).
  • Go to basic_page → Manage form display and set test_field_node edit mode to Closed.
  • Create a new basic_page node.
  • Add a paragraph and fill test_paragraph_field with one or more items, then save.
  • Edit the created node (all paragraph items will appear closed).
  • Open and edit one or more paragraph items.

Result

An additional empty item is automatically added.

Expected result

No extra empty item should be created or displayed.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

artyom hovasapyan created an issue. See original summary.

mably made their first commit to this issue’s fork.

mably’s picture

Thanks for the detailed reproduction steps and the screencast — they made it straightforward to reproduce locally and write a regression test for the exact flow.

Root cause: with edit_mode = closed, the inner subform isn't rendered on the initial form GET, so the inner field's first render happens on the AJAX rebuild that fires when you click the paragraph's Edit button. The previous fix's "skip strip on user-action rebuilds" rule treated any AJAX trigger as a count-changing user action, so the strip + items_count alignment never ran on that first render — and an extra empty row leaked in beneath the saved value.

Narrowed the rule: only the multi-value field's own Add another / Remove buttons (_add_more / _remove_button name suffixes) now count as items_count-changing actions. Paragraph open/close, validation re-renders, and other AJAX rebuilds go through the normal strip + alignment path.

Added testClosedModeParagraphOpenHidesTrailingEmpty reproducing your exact steps. Verified to fail on 1.x without the fix and pass with it; full suite (18 tests, 202 assertions) green locally.

Pushed to 3587778-extra-empty-item on the issue fork; MR coming. Could you give it a try when you have a moment and confirm whether it resolves what you saw on your end?

mably’s picture

Assigned: artyom hovasapyan » Unassigned
Status: Needs work » Needs review
artyom hovasapyan’s picture

I tried it, and it worked perfectly! It would be awesome if someone else could test it too.

mably’s picture

Status: Needs review » Reviewed & tested by the community

Let’s merge this for now, I don’t think there are many users besides us.

  • mably committed e78395f9 on 1.x
    fix: #3587778 Extra empty item appears with ‘Hide when empty’ when...
mably’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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