Make 'state:visible' js callback support multiple fields

Created on 4 August 2021, over 3 years ago
Updated 27 September 2023, about 1 year ago

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

🐛 Bug report
Status

Fixed

Version

4.0

Component

Javascript

Created by

🇦🇺Australia eric.chenchao

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024