feat(options): Images tab conditional background-image options with server-side initial visibility (Prompt Q)

config.xml: Images background block reordered to backgroundimage,
bodybackgroundcolor, then the three image-detail children
(backgroundimagefixed/display/file, all parent="backgroundimage") —
the color stays directly below the Yes/No choice, the details only
matter when an image is shown.

options.twig: the .option-visibility wrapper now gets a server-side
d-none at render time when the parent buttons group's current value is
not the show-value, so the initial state matches the stored value even
before/without options.js; options.js updateVisibilityByParent() keeps
toggling on change (idempotent, verified by jsdom test).

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
Tammo ter Hark 2026-11-25 08:46:34 +01:00
commit 365b60a9b4

View file

@ -310,7 +310,22 @@
{# parent != '': this field is only visible when the parent option is "on"
(options.js toggles .option-visibility via data-show-if-parent);
the field itself is additionally disabled via data-parent/selector_radio_childfield #}
<div class="{{ wrapClass }} {% if attr.parent != '' %}option-visibility{% endif %}"
{# Prompt Q: server-side INITIAL visibility — when the parent is a buttons
group, add d-none at render time unless the parent's current value is
the show-value ("on"). Same source of truth as currentValue (stored
options JSON, fallback oParentOptions). options.js updateVisibilityByParent()
toggles the same class on change (idempotent with this initial state).
Non-buttons parents (e.g. font's self-parent dropdown) have no radio
inputs -> options.js always shows them, so no d-none here. #}
{% set bParentHidden = false %}
{% if attr.parent != '' %}
{% set parentAttr = aOptionAttributes.optionAttributes[attr.parent] ?? null %}
{% if parentAttr is not null and parentAttr.type == 'buttons' %}
{% set parentValue = bGeneralInherit ? 'inherit' : (aCurrentOptions[attr.parent] is defined ? aCurrentOptions[attr.parent] : (oParentOptions[attr.parent] is defined ? oParentOptions[attr.parent] : '')) %}
{% if parentValue != 'on' %}{% set bParentHidden = true %}{% endif %}
{% endif %}
{% endif %}
<div class="{{ wrapClass }} {% if attr.parent != '' %}option-visibility{% if bParentHidden %} d-none{% endif %}{% endif %}"
{% if attr.parent != '' %}data-show-if-parent="{{ attr.parent }}" data-show-if-value="on"{% endif %}>
<div class="mb-3">
{# label ALWAYS above the control, for every type incl. checkbox (Prompt G) #}