Skip to content

[Bug] List field "Expand All / Collapse All" buttons not rendered in "top" position when using controls: both #2503

@olygoelements

Description

@olygoelements

In forms/fields/list/list.html.twig, the collapsible variable is computed inside the {% for key, val in value %} loop (line ~90), which means it is undefined at the time the top block of collection-actions is rendered.

Result : When using controls: both in a blueprint list field, the "Expand All" and "Collapse All" buttons appear correctly at the bottom of the list, but are missing at the top.

To reproduce :

yaml
  type: list
  style: vertical
  controls: both
  collapsed: true
  btnLabel: 'Add item'
  fields:
    .field_a:
      type: text
      label: 'Field A'
    .field_b:
      type: text
      label: 'Field B'

Expected : "Expand All", "Collapse All" and "+ Add item" buttons visible both at top and bottom.
Actual : Only "+ Add item" appears at top. "Expand All" / "Collapse All" are missing at top.

Root cause :

twig
{# In list.html.twig — collapsible is set here, INSIDE the for loop #}
{% for key, val in value %}
    {% set collapsible = field.fields|length > 1 and ... %}  {# ← too late #}
But the top block is rendered before this loop :
twig{% if fieldControls in ['top', 'both'] %}
    <div class="collection-actions">
        {% if collapsible %}   {# ← undefined here, evaluates to false #}

Fix :
Move the collapsible declaration before {% block contents %} :

twig
{% set fieldControls = field.controls|default('bottom') %}

{# FIX: compute collapsible before block contents so it's available in both top AND bottom collection-actions #}
{% set collapsible = field.fields is defined and field.fields|length > 1 and (field.collapsible is not defined or field.collapsible) %}

{% block contents %}

This one-line move makes collapsible available to both the top and bottom collection-actions blocks without changing any other behavior.

Affected file :
user/plugins/form/templates/forms/fields/list/list.html.twig
(also reproduced in user/plugins/admin/themes/grav/templates/forms/fields/list/list.html.twig)
Grav version : tested on 1.7.x
Plugin form version : tested on current

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions