mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
added missing maxLength validation
This commit is contained in:
parent
2e92b89b54
commit
d6c39e7d36
@ -152,7 +152,6 @@ class TextareaField extends FormField
|
|||||||
return $attributes;
|
return $attributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
@ -167,6 +166,41 @@ class TextareaField extends FormField
|
|||||||
return $parent;
|
return $parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate this field
|
||||||
|
*
|
||||||
|
* @param Validator $validator
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
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' => $name, 'maxLength' => $this->maxLength]
|
||||||
|
),
|
||||||
|
"validation"
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSchemaValidation()
|
||||||
|
{
|
||||||
|
$rules = parent::getSchemaValidation();
|
||||||
|
if ($this->getMaxLength()) {
|
||||||
|
$rules['max'] = [
|
||||||
|
'length' => $this->getMaxLength(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return $rules;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return value with all values encoded in html entities
|
* Return value with all values encoded in html entities
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user