Merge pull request #9999 from GuySartorelli/patch-2

ENH Use text field's title for validation messages.
This commit is contained in:
Steve Boyd 2021-08-05 15:47:03 +12:00 committed by GitHub
commit d120367b5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -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"
);