Problem/Motivation

When I use Drupal states API to set field_group visible based on another field, in the 'state:visible' callback, multiple fields are found instead of one field. This makes conditionalFieldsSavedRequired checking not working properly.

It is noted that I have not applied patch to make field_group working with conditional_fields. However conditional_fields js will still be triggered in the `state:visible` event.

Steps to reproduce

- install conditional_fields, field_group, contact modules
- create a new contact form called 'customer form'
- create a field called 'field_existing_customer' of the radio type with value 'yes' and 'no'
- create a field called 'field_customer_name' of the textfield type and make it required
- create a field called 'field_customer_number' of the radio type and make it optional
- create a field called 'field_other_info' of the radio type and make it required
- go to 'Manage form display' page
- create a field group called 'group_customer_details'
- move field_customer_name and field_customer_number to the field group 'group_customer_details'
- go to conditional_fields page to make field field_other_info display when the value of field_existing_customer is 'no'
- field group hook to make field group display when the value field_exisitng_customer is 'yes'

          $element[$key]['#states'] = [
            'visible' => [
              ':input[name="field_exisitng_customer"]' => ['value' => 'yes'],
            ],
          ];

when choosing `field_existing_customer` to yes, the field group is shown up. However all fields including required and optional are all marked as required by conditional_fields

Proposed resolution

Loop fields found in the 'state:visible' callback

Remaining tasks

N/A

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

eric.chenchao created an issue. See original summary.

eric.chenchao’s picture

I have created MR. But not sure if the build can be triggered. So I attach the patch here still.

eric.chenchao’s picture

Status: Active » Needs review
sergiuteaca’s picture

Status: Needs review » Reviewed & tested by the community

@eric.chenchao Thanks for the patch. It works on my project where I have conditional_fields and field_group modules.

  • heddn committed 9e23e3d8 on 4.x authored by eric.chenchao
    Issue #3226630 by eric.chenchao, sergiuteaca, heddn: Make 'state:visible...
heddn’s picture

Status: Reviewed & tested by the community » Fixed
heddn’s picture

Thanks for your contributions.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.