Skip to content

[4.x]: Validation error messages for related message show the field handle instead of the name #13807

Closed
@MoritzLost

Description

@MoritzLost

What happened?

Description

The new and improved error messages for validation errors in related elements don't show the field name. Instead, they show a capitalized version of the field handle. For example, I have an Assets field with name Headerbild (in German) and handle header_image. If a validation error occurs in the related asset, I'm getting this error message (in English and German, respectively):

Error: Validation errors found in Header Image asset; please fix them.

Fehler: Validierungsfehler gefunden in Header Image (Asset); bitte beheben.

In English this is barely passable, in German it's completely unusable, because the field handles often are not obvious to the client.

Steps to reproduce

  1. Attempt to save an element with an Assets field where an Asset with a missing required field is selected.

Expected behavior

The error message should always show the field name instead of the field handle. Also, the field name should be highlighted in some way to clearly separate it from the rest of the sentence, otherwise the message can become unreadable if the field label name includes multiple words. For example, the field name could be emphasized (e.g. using <strong> or <em>) or enclosed in quotation marks.

Actual behavior

The error message shows a transformed version of the field handle (header_image -> Header Image). I think this happens because the validation error uses the attribute label: $this->getAttributeLabel($this->handle)

Not sure if this is caused by us not having translations for field names. As far as I can tell, the Field base class doesn't define an attribute label for the field handle. This means the attribute labels always falls back to Model::generateAttributeLabel, which performs the transformation mentioned above.

Even if this can be fixed by adding translations, this shouldn't be required. Lots of projects, even multi-lingual sites, don't bother adding translations for all Control Panel texts, and it definitely isn't the norm for single-language projects.

Craft CMS version

4.5.6.1

PHP version

8.2

Operating system and version

macOS

Database type and version

MySQL 8.0

Image driver and version

No response

Installed plugins and versions

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions