From e4e4b0924deeb6e2f254de1b44a8e72ce9af9cf7 Mon Sep 17 00:00:00 2001 From: GuySartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Tue, 29 Jun 2021 17:45:01 +1200 Subject: [PATCH] ENH Use text field's title for validation messages. Where a field has a title, this is preferred over the field name in validation messages, as that is the "name" of the field as presented to the user. --- src/Forms/TextField.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Forms/TextField.php b/src/Forms/TextField.php index de6c96687..f1e171b78 100644 --- a/src/Forms/TextField.php +++ b/src/Forms/TextField.php @@ -142,12 +142,13 @@ class TextField extends FormField implements TippableFieldInterface public function validate($validator) { if (!is_null($this->maxLength) && mb_strlen($this->value) > $this->maxLength) { + $name = strip_tags($this->Title() ? $this->Title() : $this->getName()); $validator->validationError( $this->name, _t( 'SilverStripe\\Forms\\TextField.VALIDATEMAXLENGTH', 'The value for {name} must not exceed {maxLength} characters in length', - ['name' => $this->getName(), 'maxLength' => $this->maxLength] + ['name' => $name, 'maxLength' => $this->maxLength] ), "validation" );