Problem/Motivation
Validation errors from an untriggered dependent should be removed so that fields excluded by a dependency do not prevent the form from saving.
However, ConditionalFieldsFormHelper::dependentValidate() returns as soon as it finds an error:
if (!empty($field_errors)) { $form_state_addition['errors'] = $field_errors; return; }
The dependent is normally registered in conditional_fields_untriggered_dependents immediately after this block. Because of the early return, a dependent that has an error is never registered.
formValidate() therefore has no record of the dependent and cannot remove its validation errors. The fields that most need this handling are precisely the ones excluded from it.
This is the behaviour reported in #3344587: Support for field hidden by condition losing its required status. It reproduces on a normal entity form and is not specific to Inline Entity Form.
Steps to reproduce
- On Article, add a plain text field
field_trigger. - Make Body required.
- Make Body depend on
field_trigger: state Unchanged, condition Value, valuetrigger. - Add an Article. Give it a title, enter something other than
triggerinfield_trigger, leave Body empty, and save.
Actual: Drupal reports Body field is required. and the node is not saved.
Expected: The dependency is untriggered, so the Body validation error is removed and the node saves.
Proposed resolution
Register errored untriggered dependents in conditional_fields_untriggered_dependents so that formValidate() can remove their errors.
Remaining tasks
- Determine whether to register
$form_state_additionbefore retaining the earlyreturn, or remove the early return entirely. - Add functional coverage for an untriggered dependent with a Drupal validation error.
ConditionalFieldNumberZeroRequiredTest does not cover this path. It tests the conditional required state, where the validation error is never created in the first place.
Comments
Comment #2
joelpittetAlso likely related #3344587: Support for field hidden by condition losing its required status