{#- One part of a form's layout: a field, or the fields a row, a column, a fieldset, a panel inside another or a set of tabs holds. `rows` maps a path to its form row, and `wrong` lists the paths with a mistake. -#} {% macro part(piece, rows, wrong) -%} {%- if piece.kind == "field" -%} {%- set row = rows[piece.path] -%} {%- set hide_label = not piece.show_label -%} {% include "adminsite/_field.html" %} {%- elif piece.kind == "row" -%} {#- Side by side once there is room, one under the other on a phone. -#}
{%- for child in piece.children %}{{ part(child, rows, wrong) }}{% endfor -%}
{%- elif piece.kind == "column" -%}
{%- for child in piece.children %}{{ part(child, rows, wrong) }}{% endfor -%}
{%- elif piece.kind == "fieldset" -%}
{{ piece.title }} {%- for child in piece.children %}{{ part(child, rows, wrong) }}{% endfor -%}
{%- elif piece.kind == "panel" -%} {#- A panel inside another part reads as a titled stretch of it. -#}

{{ piece.title }}

{%- if piece.description %}

{{ piece.description }}

{% endif -%}
{%- for child in piece.children %}{{ part(child, rows, wrong) }}{% endfor -%}
{%- elif piece.kind == "tabs" -%} {#- One tab at a time, opening on the first that holds a mistake, with a mark on each that does. The arrow keys move between them. The line under them is drawn inside the bar, as above a list. -#} {%- set tabs_id = "tabs-" ~ (piece.paths()|first)|replace(".", "-") -%} {%- set count = piece.children|length -%} {%- set start = namespace(index=0, found=false) -%} {#- No filter on the loop: a filtered loop counts only what it keeps. -#} {%- for tab in piece.children -%} {%- if not start.found and tab.paths()|select("in", wrong)|list -%} {%- set start.index = loop.index0 -%}{%- set start.found = true -%} {%- endif -%} {%- endfor -%}
{%- for tab in piece.children %} {%- set index = loop.index0 %} {%- endfor %}
{%- for tab in piece.children %}
{%- for child in tab.children %}{{ part(child, rows, wrong) }}{% endfor -%}
{%- endfor %}
{%- endif -%} {%- endmacro %}