mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
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.
This commit is contained in:
parent
82e0d8f24b
commit
e4e4b0924d
@ -142,12 +142,13 @@ class TextField extends FormField implements TippableFieldInterface
|
|||||||
public function validate($validator)
|
public function validate($validator)
|
||||||
{
|
{
|
||||||
if (!is_null($this->maxLength) && mb_strlen($this->value) > $this->maxLength) {
|
if (!is_null($this->maxLength) && mb_strlen($this->value) > $this->maxLength) {
|
||||||
|
$name = strip_tags($this->Title() ? $this->Title() : $this->getName());
|
||||||
$validator->validationError(
|
$validator->validationError(
|
||||||
$this->name,
|
$this->name,
|
||||||
_t(
|
_t(
|
||||||
'SilverStripe\\Forms\\TextField.VALIDATEMAXLENGTH',
|
'SilverStripe\\Forms\\TextField.VALIDATEMAXLENGTH',
|
||||||
'The value for {name} must not exceed {maxLength} characters in length',
|
'The value for {name} must not exceed {maxLength} characters in length',
|
||||||
['name' => $this->getName(), 'maxLength' => $this->maxLength]
|
['name' => $name, 'maxLength' => $this->maxLength]
|
||||||
),
|
),
|
||||||
"validation"
|
"validation"
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user