Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when form API 'text_format' element is hidden by #states, Formatting options still visible #5259

Open
jenlampton opened this issue Sep 27, 2021 · 5 comments · May be fixed by backdrop/backdrop#3784

Comments

@jenlampton
Copy link
Member

jenlampton commented Sep 27, 2021

Description of the bug

If you set up '#type' => 'text_format' field on a form, and try to apply #states to it to show/hide it, things do not work as expected.

Steps To Reproduce

To reproduce the behavior:

  1. Place the following code into a form (custom module, or existing form):
    $form['my_checkbox'] = array(
      '#type' => 'checkbox',
      '#title' => t('Toggle the text format on/off'),
      '#description' => t('Tick/untick me to show/hide a text format field below.'),
    );
    $form['my_text_format'] = array(
      '#type' => 'text_format',
      '#title' => t('Text format'),
      '#description' => t('The "Formatting options" fieldset should NOT be shown when the text format is hidden.'),
      '#states' => array(
        'visible' => array(
          ':input[name="my_checkbox"]' => array('checked' => TRUE),
        ),
      ),
    );
  2. Toggle the checkbox on form...

Actual behavior
image

  • The text format field itself is hidden 👍🏼
  • The "Formatting options" fieldset and the help/description of the text format field are NOT hidden 👎🏼

Expected behavior

The "Formatting options" fieldset and the help/description of the text format field should be hidden

Additional information

Add any other information that could help, such as:

  • Backdrop CMS version: 1.20.0
@jenlampton jenlampton changed the title when forma API 'text_format' element is hidden by #states, format selection fieldset still shown when form API 'text_format' element is hidden by #states, Formatting options still visible Sep 27, 2021
@indigoxela
Copy link
Member

The problem is that text_format has a theme wrapper (text_format_wrapper), which contains the form element and the filter fieldset. The state only triggers the form element, not the filter element.

I see no easy way to change that without breaking changes.

@klonos
Copy link
Member

klonos commented Oct 5, 2021

I see no easy way to change that without breaking changes.

How about this?: backdrop/backdrop#3784 😉

HTML before:
image

...and after:
image

@klonos
Copy link
Member

klonos commented Oct 5, 2021

...inspiration/credit to our Drupal brethren: https://www.drupal.org/project/drupal/issues/997826 ...although they only fixed the fieldset, and missed the #description. I'll file a PR/patch for Drupal if I find the time/energy, otherwise I will at the very least let them know.

@klonos
Copy link
Member

klonos commented Oct 5, 2021

I should mention that this is yet another issue that suffers from #5157.

@klonos
Copy link
Member

klonos commented Oct 7, 2021

@jenlampton did you get a chance to test this on the site that you were having the issue with?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants