Closed (cannot reproduce)
Project:
Multi-Value Add Form Hider
Version:
1.0.0
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
21 Apr 2026 at 08:24 UTC
Updated:
28 Apr 2026 at 20:52 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
mably commentedAre you sure it works fine without the module installed?
Comment #3
artyom hovasapyan commentedComment #4
artyom hovasapyan commented#2 Yes, it works correctly without the module installed.
Comment #5
mably commentedCan you provide a full reproducible scenario from a fresh Drupal 11 instance please?
And the corresponding stack trace?
I couldn't reproduce the problem locally.
Comment #6
artyom hovasapyan commentedComment #7
artyom hovasapyan commentedUpdate description.
Comment #9
mably commentedOk, have been able to reproduce the display glitch using this issue's Tugboat instance.
IIUC you need to click twice on the "Add another item" instead of once. Will investigate further.
Comment #10
mably commented@artyom-hovasapyan it should be fixed.
Can you validate it's fixed in this issue's Tugboat instance?
https://mr1-lqpdvzx0hn6insnsaxzsd0jlpgx0qe0f.tugboatqa.com/
Account: admin / admin
Once validated, I'll publish a new release.
Comment #11
artyom hovasapyan commented@mably Nice 🙂
I tested it and it works as expected, but I couldn’t verify the same functionality when the field is inside a Paragraph.
Comment #13
mably commentedSeems to work fine with Paragraphs, merging. Thanks!
Comment #15
artyom hovasapyan commentedProblem: Paragraph field behavior is inconsistent.
When the field has no items, the “Add new item” button works as expected.
However, if existing paragraph items contain empty values, the “Add new item” functionality breaks and no longer works correctly.
Comment #16
mably commentedI'm not sure I understand why it would behave differently within a paragraph.
Could you provide a fully reproducible scenario on a fresh Drupal 11 instance, including detailed steps and the actual result versus the expected result?
EDIT: Looks like I've been able to reproduce the problem shown in your video. Investigating.
Comment #17
artyom hovasapyan commentedParagraph fields use more complex AJAX and entity-based handling than standard multivalue fields, so this difference in behavior might be caused by that additional layer of processing.
I do this on drupla 10.
Comment #18
artyom hovasapyan commented#16 I’ll try to reproduce it on `fresh drupal 11` and ping you back.
Comment #19
artyom hovasapyan commentedThis problem also exists on a clean Drupal 11 setup.
Comment #21
artyom hovasapyan commentedI created a module similar to yours, and it works. It might be useful to merge some parts, or it could help you improve your implementation.
I also think that if this can be implemented using only a .module hook, the issue might already be fixable at the core level.
What do you think about this patch?
Comment #22
artyom hovasapyan commentedFor paragraph fixed but The patch doesn’t work correctly— it also breaks other functionality(when click `add new item` create 2 items).
Comment #23
mably commentedReopening — managed to reproduce the inner-field scenario you described and the previous fix has a real regression there.
Repro
multi_value_add_hidersetting on the outer reference).hide_empty_add_form = not_emptyon its widget.Root cause
The Apr 22 fix counts non-empty items in the rebuilt
$itemslist and strips the trailing widget when it is empty. On a regular AJAX rebuild that's fine, but on the rebuild produced by the inner field's "Add another" click, the typed value lands in$items[0]as non-empty, the trailing widget our hook tries to add ends up being treated as the empty one to strip, and the freshly added widget the user explicitly asked for is removed.Fix
Skip the trim entirely when the rebuild was triggered by an
_add_morebutton. Both core'sWidgetBaseand the Paragraphs widget name their AJAX add buttons with that suffix, so a singlestr_ends_with($triggering_element['#name'] ?? '', '_add_more')guard covers both. When the user explicitly clicks "Add another", we never strip — the whole point of the click is to expose an extra empty widget.Tests
Added
MultiValueAddHiderParagraphsTestwith two methods reproducing the inner-field flow:testInnerAddAnotherWithoutTyping— locks the case you said works.testInnerAddAnotherAfterTypingValue— fails on the pre-fix code, passes with the fix.Also hardened
testTrailingEmptyHiddenAfterFirstValueNotEmptyModeagainst an intermittent flake observed under load (waits for the second input and the post-submit success message before asserting on them). Three sequential full-suite runs locally are now green and stable.MR
See !2 on branch
3585946-paragraphs-add-another. Addsdrupal/paragraphstorequire-devso CI and downstream contributors can run the new test.Comment #24
mably commented@artyom-hovasapyan I don't understand your last video, can you explain please?
EDIT: Ok, it might be that in "Always" mode, clicking on "Add more" adds two empty fields. Working on it.
Comment #25
mably commented@artyom-hovasapyan can you give it another try please?
I couldn't reproduce any bug locally.
Test coverage has been improved accordingly.
Comment #26
artyom hovasapyan commentedFor a simple content type field, everything works correctly.
However, for fields inside paragraphs, the behavior is inconsistent — sometimes it works(when preview field contain text), sometimes it doesn’t.
I’ve also recorded a video to demonstrate the issue.
Comment #27
artyom hovasapyan commentedComment #28
artyom hovasapyan commentedI tried it, and it worked perfectly! It would be awesome if someone else could test it too.
Comment #29
mably commentedQuick update — several follow-up scenarios surfaced while validating the fix locally. The MR has been iterated through them and now converges on a single, consistent model. Sharing the model in case it's useful for review.
The model
Each
hide_empty_add_formmode falls into one of two categories based on whethershould_hidecan flip between renders due to user-typed content:not_empty(always), andnot_requiredon a required field (whereshould_hide = non_empty >= 1 || !requiredreduces tonon_empty >= 1because!requiredis FALSE). In these, the trailing empty widget is part of the user's working area as soon as content exists; user-action rebuilds must skip the strip, and the initial-render strip must be paired with anitems_countdecrement so subsequent clicks don't double-bump the visible count.always, andnot_requiredon an optional field.should_hideis always TRUE, so the hook strips on every render.items_countand visible stay in sync naturally and clicks correctly add one row at a time. No decrement here; decrementing in these modes immediately undoes the user's next click.Both branches converge on the same invariant: every "Add another" click adds exactly one visible row, every "Remove" click drops exactly one row.
Bugs the iteration uncovered
not_emptymode + saved-populated paragraph + click was producing two empty fields per click (drift between the initial-render strip and subsequent SKIPs).not_requiredmode + optional empty + click + type + click was producing 2 visible inputs after the second click instead of 1 (mode contract should hold across clicks).alwaysmode + add-and-fill + click was visibly doing nothing (the early always-mode test only covered the empty-initial single click, not a populated multi-click).alwaysmode + click + type + click cycles where the first click stayed at 1 visible after a misguideditems_countdecrement on every strip.not_emptymode + Remove on a populated paragraph dropped two rows at once (the strip ran on top of the user-removed delta).not_requiredmode + required field + type + click silently did nothing (same pattern as the original ticket, in a different mode).Test coverage
16 methods, 182 assertions, locally green. Each new test was verified to fail on the prior buggy hook with a specific assertion message before the fix was committed.
extractFormValuesbehavior).MR
!2 at
c9772e2.Apologies for the noise on the MR — should be stable now. Happy to walk through the model or any specific commit if helpful.
Comment #30
mably commentedComment #31
artyom hovasapyan commentedTested, works fine.
Comment #32
mably commentedOk, let's merge this!
Comment #34
mably commentedComment #36
artyom hovasapyan commentedI double check and not work.
Don't hide after content save.
Comment #37
artyom hovasapyan commentedComment #38
mably commented@artyom-hovasapyan could you please describe in detail the behavior you’re observing so I can reproduce it locally?
May be you could create a dedicated ticket for this new issue?
Unless this is a regression introduced by this issue's fixes ofc.
Comment #39
artyom hovasapyan commentedImproved:
This issue is related to this ticket.
Steps to reproduce:
Create a node with a multivalue (unlimited) field and enable the “Hide when field is not empty” option.
Add values to the field and save the content.
Edit the node again.
Result:
An extra empty item appears in the field.
Comment #40
mably commentedSadly, I cannot reproduce your test scenario locally.
Is it from a fresh Drupal 11 instance?
Comment #41
mably commentedA new test has been added that implement the described scenario:
https://git.drupalcode.org/project/multi_value_add_hider/-/commit/e5c2be...
The test passes fine.
Closing for now as "Cannot reproduce".