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
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | conditional_fields-3226630-2-state-visible-multiple-fields.patch | 1.78 KB | eric.chenchao |
Issue fork conditional_fields-3226630
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
Comment #3
eric.chenchao commentedI have created MR. But not sure if the build can be triggered. So I attach the patch here still.
Comment #4
eric.chenchao commentedComment #5
sergiuteaca commented@eric.chenchao Thanks for the patch. It works on my project where I have conditional_fields and field_group modules.
Comment #7
heddnComment #8
heddnThanks for your contributions.