You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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),
),
),
);
Toggle the checkbox on form...
Actual behavior
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
The text was updated successfully, but these errors were encountered:
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
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.
...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.
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:
Actual behavior
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:
The text was updated successfully, but these errors were encountered: