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
- Configure an node type with
- required field
field_dependee. - optional field
field_dependent.
- required field
- Configure a field condition so that
field_dependentbecomes required whenfield_dependeehas no value. - Open the creation form page for the node type.
- Disable frontend form validation (https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/form#novalidate).
- Submit the form without filling any field.
- Expect the required error message for
field_dependeeandfield_dependentto 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.
Issue fork conditional_fields-3519010
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
tgaugesComment #4
tgaugesPlease review :)
Comment #5
tgaugesI added the feature to respect the
#required_errorproperty but the test is failing. It needs to be fixed.