#states array ignored for config forms when placing paragraphs

Created on 3 February 2025, 2 months ago

Problem/Motivation

The Block config form for the Google AdSense block includes a number of conditional fields that are controlled by the #states array. This works as expected in the core Block Layout UI. However, those conditions are ignored when the form is accessed via Layout Paragraphs.

Specifically, the Width, Height, and Layout Key form elements should not be visible or enabled unless the Ad Format form element is set to "Custom."

Screenshot of the form in the Blocks UI:

Screenshot of the form in the Layout Paragraphs UI:

Example of the form array for the Height field as provided by the Google AdSense module:


    $form['ad_height'] = [
      '#type' => 'number',
      '#title' => $this->t('Height'),
      '#default_value' => $this->configuration['ad_height'],
      '#description' => $this->t('Custom ad height.'),
      '#field_suffix' => ' ' . $this->t('pixels'),
      '#size' => 3,
      '#maxlength' => 4,
      '#min' => 50,
      '#max' => 1200,
      '#states' => [
        'enabled' => [
          ':input[name="settings[ad_format]"]' => ['value' => 'custom'],
        ],
        'visible' => [
          ':input[name="settings[ad_format]"]' => ['value' => 'custom'],
        ],
        'required' => [
          ':input[name="settings[ad_format]"]' => ['value' => 'custom'],
        ],
      ],
    ];

πŸ› Bug report
Status

Active

Version

2.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jesss

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024