Conditional Fields Not Resetting in Paragraph Subforms on Drupal 10.2

Created on 27 January 2025, 4 days ago

Problem/Motivation

In a Drupal 10.2 environment with PHP 8.1, I have configured a content type named 'medical_form' which includes an entity reference field to a paragraph type called 'medical_form_fields'. Both the content type and the paragraph type utilize the Conditional Fields module to manage field dependencies.

The issue arises within the paragraph subform:

  1. Persistent Values in Dependent Fields:
    • When a dependency is triggered, and a user inputs data into the dependent field, if the dependency is subsequently untriggered before form submission, the dependent field retains its value upon submission instead of submitting an empty value.
  2. Required Field Validation Errors:
    • If a dependent field within the paragraph subform is marked as required, the form throws a validation error upon submission, even when its dependency is not triggered, preventing the form from being submitted.
    • Notably, these issues do not occur when Conditional Fields are applied directly to fields within the 'medical_form' content type; they are specific to the use of Conditional Fields within paragraph subforms.

Steps to reproduce

  1. Create a content type named 'medical_form'.
  2. Add various fields to 'medical_form' and apply Conditional Fields to establish dependencies.
  3. Create a paragraph type named 'medical_form_fields' containing multiple fields.
  4. Apply Conditional Fields within 'medical_form_fields' to set up dependencies among its fields.
  5. Add 'medical_form_fields' as an entity reference field to the 'medical_form' content type.
  6. On the 'medical_form' node add/edit form:
    • Trigger a dependency within the paragraph subform fields.
    • Enter values into the dependent field.
    • Untrigger the dependency.
    • Submit the form.

Proposed resolution

The Conditional Fields module should be enhanced to handle dependencies within paragraph subforms appropriately. Specifically:

  • Ensure that when a dependency is untriggered, any data entered in the now-hidden dependent fields is not retained upon form submission, resulting in empty values for those fields.
  • Adjust validation logic so that required fields within paragraph subforms do not trigger validation errors when their dependencies are not active, allowing the form to submit successfully.

Remaining tasks

  • Investigate the Conditional Fields module's handling of dependencies within paragraph subforms.
  • Develop and test a patch to address the identified issues.
  • Update documentation to reflect the changes and provide guidance on using Conditional Fields within paragraph subforms.

User interface changes

No user interface changes are anticipated.

API changes

No API changes are anticipated.

Data model changes

No data model changes are anticipated.

🐛 Bug report
Status

Active

Version

4.0

Component

Code

Created by

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