Field group #states interferes with children #states

Created on 6 February 2023, almost 2 years ago
Updated 5 October 2023, about 1 year ago

Problem/Motivation

It seems that adding a dependency to a field group that affects its visibility seems to interfere with the dependencies of the field group children.

Steps to reproduce

- Create a control field and field group that contains a selection of text fields
- Add a dependency where the control field affects the visibility of the field group
- Add a dependency on the first child field where the control field affects its required state.
- When the control field makes the group become visible, all child fields are marked as required.
- If you change the field group dependency is changed from Visible to Unchanged only the correct field is marked as required when using the control field.

🐛 Bug report
Status

Active

Version

3.4

Component

Code

Created by

🇬🇧United Kingdom very_random_man

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

Comments & Activities

  • Issue created by @very_random_man
  • 🇬🇧United Kingdom very_random_man

    Actually, I think this is more likely a Field Group issue as it still happens if I remove the Conditional Fields dependencies and use various form hooks to apply #states directly.

    Some more detail:
    - I have field group tabs and inside one of those I have a checkboxes element and a fieldset containing text fields.
    - I have used hook_form_alter to add #states to make one of the text fields required depending on a checkbox value.
    - I have used hook_field_group_form_process_alter (and a tried bunch of other similar hooks) to add #states to make the fieldset visible depending on the same checkbox value as per https://www.drupal.org/project/field_group/issues/1053174#comment-14138494 💬 hook_form_alter form state problems Closed: works as designed

    What happens is that when there is a #states value on the fieldset, the required state is applied to all the text fields inside it.

  • 🇨🇦Canada liquidcms

    I have used Conditional Fields module to make a field group visible (or not) and can confirm that once the FGis made visible; all the fields within it are made required. The red star even shows on the label for the FG itself.

Production build 0.71.5 2024