Dependent field is always required even if hidden with Inline entity form

Created on 11 March 2024, 9 months ago
Updated 25 March 2024, 8 months ago

Problem/Motivation

Conditional fields do not work as expected in connection with Inline entity form module form widgets used on fields added in a condition environment.

Steps to reproduce

This example uses the content types "Article" and "Basic page". Feel free to use your own 2 different content types. And it needs Inline Entity form module installed.

1. Add a "Select List"(Checkbox/Radio) field along with a "Plain text" in content type "Article" and make sure both are set to required.
2. Create a new entity reference field in the second content type "Basic Page" and reference it with the above content type "Article".
3. Select "Inline entity form" in the Manage form display for the above added entity reference field in Article.
4. Navigate to condition field setting and create a new condition for Article content type fields where the text field is only visible when a specific checkbox is selected.
5. Create a new Basic Page content and try to save the content by checking an option of the select field which will not display the text field.
6. You will get an error, stating that the hidden field (Plain text) is required, which shouldn't come.

Proposed resolution

The error for the invisible field should be overridden and should not display.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Postponed: needs info

Version

4.0

Component

Code

Created by

🇮🇳India saurabh-2k17

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

Comments & Activities

  • Issue created by @saurabh-2k17
  • Issue was unassigned.
  • Status changed to Needs review 9 months ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update 9 months ago
    130 pass
  • 🇮🇳India saurabh-2k17

    Hi, attaching a working patch for this. Thanks to @star-szr for the help!

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update 9 months ago
    130 pass
  • 🇨🇦Canada star-szr

    Attaching an updated patch that properly handles the field specificity (otherwise errors on all fields within the IEF will be skipped) and adds one defensive check.

  • Status changed to Postponed: needs info 9 months ago
  • 🇫🇷France dqd London | N.Y.C | Paris | Hamburg | Berlin

    Thanks for the report and work in here! +1

    Please test if this happens only if Inline Entity Form is used which is assumed by reading the report as-is. If yes then the title and summary needs to be more specific. I changed it accordingly in assumption that it is so, but please, remove this if it not the case.

    Some nit picks: please do not use abbreviations in issue summaries. Drupal.org is a multi-language user base driven community and some people have a hard time to follow texts with abbreviated words. Especially if not used consequently in the same way (edited issue summary).

    Apart from that this issue has some overlaps with another issue regarding hidden fields which are required. (Can somebody please help me to find it and link, refer here, no time atm)? - Please try to read/follow both issues to understand that there are different opinions on how Conditional Fields should handle this and incorporate patches from here and there.

  • 🇧🇪Belgium andreasderijcke Antwerpen / Gent

    This is not an inline entity form issue, it happens on the default entity form as well.

    I think the question is, is this a supported case or should setup be reversed?

    You cannot make a required field conditionally optional, but you can make it conditionally required.
    The latter makes more sense to me, as the given case demands it to be required only when the checkbox is selected.

    Also, doesn't field validation complain about the text field being empty when the specific checkbox isn't selected?
    I would expect that, unless you have set a default value for the text field. This also make this feel more like a setup problem.

  • 🇨🇦Canada star-szr

    This issue is specific to inline entity form (or at least forms-within-forms), it could potentially be incorporated into the linked issue at a later time, but I don't want to add to the confusion at this point.

Production build 0.71.5 2024