The simple widget uses multiple_values = false, allowing Drupal to repeat the widget for each delta.
This gave us simplicity of implementation, but we also inherited the UX problems inherent to this approach.

Problems:
1) No way to delete an item
This UX was designed for single value widgets where empty means "remove the value".
IEF can't do that, so once you click "add another item", that item is there forever, since the inline form is required.
edit: added by Drupal 10.2

2) "Add another item" doesn't limit validation errors
You need to fill out the first inline form to be able to click "add another item", otherwise you get a validation error.

3) Weird titles
My field is called "Pages" and that's shown in the field heading.
But for some reason each inline form has a fieldset with its own title: "PAGES (VALUE 1)", "PAGES (VALUE 2)", etc.
The second level of titles is completely unnecessary.

#3 might be solvable in the current widget. #1 and #2 will require a more significant rework, where the Simple widget takes over the multiple value handling.

Comments

bojanz created an issue. See original summary.

robpowell’s picture

1) No way to delete an item
This UX was designed for single value widgets where empty means "remove the value".
IEF can't do that, so once you click "add another item", that item is there forever, since the inline form is required.

I think this is high priority, an author should always be able to delete a relationship in the authoring experience.

tacituseu’s picture

@1: maybe a checkbox and some jQuery applying .hidden would suffice
@3: not sure if still an issue, but it comes from defaults in Drupal\Core\Field\WidgetBase:

  '#title' => $this->t('@title (value @number)', ['@title' => $title, '@number' => $delta + 1]),
  '#title_display' => 'invisible', 

and is usually caused by some template somewhere not checking '#title_display'

Edit:
defaults sneak in 'HERE' InlineEntityFormSimple::formElement():

    $element = [
      '#type' => $this->getSetting('collapsible') ? 'details' : 'fieldset',
      '#field_title' => $this->fieldDefinition->getLabel(),
      '#after_build' => [
        [get_class($this), 'removeTranslatabilityClue'],
      ],
    ] + $element; // <-- 'HERE'

Could work on it if there is interest from maintainers, I like the simplicity of it, complex is bit too much/kludgy for my needs.

tacituseu’s picture

tacituseu’s picture

@2: Any reason not to just do something like this:

    // Remove add options if the user cannot add new entities.
    if (!$this->canAddNew()) {
      // ...
    } else {
      if (isset($element['add_more'])) {
        $element['add_more']['#limit_validation_errors'] = [];
      }
    }

in InlineEntityFormSimple::formMultipleElements(), it is set by default to [$field_name] so it reports them for it,

InlineEntityFormComplex seems to be dealing with them in the same way for its 'actions'.

tacituseu’s picture

Status: Active » Needs work
StatusFileSize
new560 bytes

Attached patch limiting errors on "Add another item"

joachim’s picture

I'm amazed our tests aren't showing this bug, because the SimpleWidgetWebTest test class simulates clicking the 'add more' button:

            $this->drupalPostAjaxForm(NULL, $edit, 'single_add_more');

Presumably this is showing up a limitation of the old simpletests?

I'm working on converting that test to Functional Javascript tests (#2974544: Convert tests from Simpletest to FunctionalJavascript), and it's failing there precisely because of this bug.

sethfisher’s picture

Anyone here looking for #1 (no way to delete an item), the multiple_fields_remove_button module is working for me (it's mentioned in the description of the drupal core issue related to this issue).

wil2091’s picture

@sethfisher - The patch provided here https://www.drupal.org/project/inline_entity_form/issues/3129760#comment... works well for #1.

geek-merlin’s picture

So we have 3 issues in this IS. We have a patch for No.2.
We have a contrib module that solves No.1 which needs documentation.
Let's move that and No.3 to separate isseus.

dcam’s picture

Drupal 10.2 adds a Remove button for the Simple widget. See #1038316: Allow for deletion of a single value of a multiple value field. I've tested it and it worked well for me.

dcam’s picture

Issue summary: View changes