Problem/Motivation

Since the dragtable widget refactor in #3258972 (released in 8.x-1.11), EntityqueueDragtableWidget::formMultipleElements() relies on core to build the per-row Remove buttons. Core's WidgetBase::formMultipleElements() only adds them, and the AJAX wrapper, when the field cardinality is unlimited.

Subqueue items fields are unlimited, so queues work. But on a regular entity reference field with limited cardinality (e.g. 1 or 7) using this widget, editors can no longer remove a referenced item. The "Add item" control is also missing, because it reuses that AJAX wrapper; empty slots are rendered as plain autocomplete rows instead. An empty single-value field offers no way to add a reference at all. In 8.x-1.10 the widget built its own AJAX wrapper, Remove buttons and "Add item" control regardless of cardinality, so this is a regression after updating.

Related: #3258972 (the refactor), #3047463.

Steps to reproduce

Reproduced with Entityqueue 8.x-1.13 on Drupal 10.6.9 and 11.4.11 (the refactor has been in every release since 8.x-1.11).

Setup: add an entity reference field with "Allowed number of values: Limited" to any entity type (e.g. a node or block content type), and use the "Autocomplete (draggable table)" widget for it.

Missing Remove button
  1. Limit the field to e.g. 7 values.
  2. Save an entity with 7 references, then reopen it for editing.

Expected: each reference has a Remove button. Actual: there is no Remove button, so editors cannot remove references using the widget.

8.x-1.10: Remove on each row 8.x-1.13: no Remove buttons
Draggable table widget in 8.x-1.10 with a Remove button on each row Draggable table widget in 8.x-1.13 without Remove buttons
Missing Add item control
  1. Limit the field to e.g. 3 values.
  2. Save an entity with 1 reference (or none), then reopen it for editing.

Expected: an "Add item" control is shown below the table. Actual: there is no "Add item" control; unused slots appear as plain autocomplete rows instead. An empty single-value field offers no way to add a reference at all.

8.x-1.13: no Add item, only an empty autocomplete row With the fix: Add item control
 no Add item control, only an empty autocomplete row  Remove button on the row and an Add item control

Workaround: set the field to unlimited cardinality (loses the item limit).

Proposed resolution

For fields with limited cardinality, in interactive (non-programmed) forms: add the AJAX wrapper, render one row per referenced item, add the per-row Remove button in the widget (reusing core's deleteSubmit()/deleteAjax()), and show "Add item" until the cardinality is reached.

Single-value fields use the table layout again, as in 8.x-1.10. Otherwise the field label and description are lost, because core does not use a table for them and the widget renders the row as a container.

Remaining tasks

  • MR
  • Tests for cardinality 1 and 2: remove (including the AJAX response), add, save, and save empty; label visible on a single-value field both filled and empty; required single-value field
  • Manual testing on Drupal 10.6
  • Review

User interface changes

Remove button and "Add item" control restored on limited-cardinality fields. Single-value fields use the table layout (as in 8.x-1.10), so the field label and description remain visible whether the field is filled or empty.

API changes

None.

Data model changes

None.


Generated with the help of an LLM.

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

cadence96 created an issue. See original summary.

cadence96’s picture

Status: Active » Needs review

Opened MR !69. The pipeline is green. Setting to Needs review.

What the MR does

  • For fields with limited cardinality, in interactive forms, the widget now adds its own AJAX wrapper, renders one row per referenced item with a Remove button (reusing core's deleteSubmit()/deleteAjax()), and shows "Add item" until the cardinality is reached.
  • Single-value fields use the table layout again, as in 8.x-1.10, so the field label and description stay visible whether the field is filled or empty.
  • Unlimited fields and subqueues are not affected. Programmed forms keep the rows core builds.



Tests added

  • Functional: cardinality 1 and 2, optional and required. Covers remove (including the AJAX response), add, save, saving an optional field empty, a required field refusing to be saved empty, and that the label, description and required marker each show once.
  • FunctionalJavascript: add and remove through real AJAX for cardinality 1 and 2.
  • Kernel: a programmed form gets none of the interactive controls.



Testing

Tested manually in the browser on Drupal 10.6.9 (a full 7-value field, and a single-value field both empty and filled: remove, add and save). Automated: all new tests pass on 11.4; on 10.6.9 (PHPUnit 9.6) the new Functional test (data-provider cases run through a small wrapper), the Kernel test and the existing widget tests in EntityQueueUiTest pass.

The code and tests were written with the help of an LLM and reviewed by me.

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

  • amateescu committed b80f228a on 8.x-1.x authored by cadence96
    fix: #3641317 Draggable table widget has no Remove button or Add item...
amateescu’s picture

Assigned: cadence96 » Unassigned
Status: Needs review » Fixed

Made a few fixes and merged into 8.x-1.x, thanks!

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.