Problem/Motivation

I want the required error message from the Conditional Fields module to be consistent with the rest of the framework.

This module can conditionally set a field as required. This is not validated in the browser via an HTML attribute but also in the backend.

Currently the required error message is '%name is required.' introduced in #2833368: Fix conditionally required fields message and label. The relevant code is src/ConditionalFieldsFormHelper.php:623.

Drupal core uses '@name field is required.' as default required error message. This can be seen in core/lib/Drupal/Core/Form/FormValidator.php:299.

The message from Drupal core is also used at multiple places.

Steps to reproduce

  1. Configure an node type with
    • required field field_dependee.
    • optional field field_dependent.
  2. Configure a field condition so that field_dependent becomes required when field_dependee has no value.
  3. Open the creation form page for the node type.
  4. Disable frontend form validation (https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/form#novalidate).
  5. Submit the form without filling any field.
  6. Expect the required error message for field_dependee and field_dependent to be identical

Proposed resolution

Use the Drupal required error message.

Remaining tasks

  • Implement test.
  • Implement solution.
  • Fix test case regarding custom required error message.

User interface changes

The required error messages are consistent.

API changes

None.

Data model changes

None.

Command icon 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

tgauges created an issue. See original summary.

tgauges’s picture

Issue summary: View changes
tgauges’s picture

Assigned: tgauges » Unassigned
Issue summary: View changes
Status: Active » Needs review

Please review :)

tgauges’s picture

Issue summary: View changes
Status: Needs review » Needs work

I added the feature to respect the #required_error property but the test is failing. It needs to be fixed.